New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate existing custom command interface #436

brian-mann opened this Issue Feb 20, 2017 · 3 comments


3 participants

brian-mann commented Feb 20, 2017

We are going to move the custom command interface to be on Cypress.Commands instead of the Cypress object.

Cypress.addParentCommand -> Cypress.Commands.add
Cypress.addChildCommand -> Cypress.Commands.add
Cypress.addDualCommand -> Cypress.Commands.add

This will be a breaking change and we'll print a good error message.

Changes to the interface

Instead of having to decide "up front" and learn about the difference between parent, child, and dual commands, you can now simply describe their "behavior" surrounding subjects to get what you want.

Custom commands will now accept an optional 2nd options argument which will describe how to handle existing subjects.

{prevSubject: false} // the default (parent command) which ignores existing subjects
{prevSubject: true} // enforces an existing subject (child command)
{prevSubject: "dom"} // enforces an existing DOM subject (child command operating on DOM)
{prevSubject: "optional"} // may or may not have an existing subject (dual command)
// example parent command
Cypress.Commands.add("login", function(username, password){
  // this works the same

// example child command
Cypress.Commands.add("rightclick", {prevSubject: "dom"}, function(subject, arg1, arg2){
  // enforces that the previous subject is DOM and the subject is yielded here
  // blows up and provides a great error when improperly chained

// example dual command
Cypress.Commands.add("foo", {prevSubject: "optional"}, function(subject, arg1, arg2){
  // subject may or may not be undefined giving you the option to change the behavior
  // the most common dual command is cy.contains() which operates differently whether
  // there is an existing subject or not

This comment has been minimized.

Andrew1431 commented Mar 14, 2017

Hey! I spent a while tracing down a bug this morning, and the error was very unclear to me. I was simply getting an error: Can not read property 'apply' of undefined when the custom method would be called.

Turns out my issue was that deleteRoom was not being exported, and as a result I was passing undefined to the addDualCommand. Could you consider adding a validator in that method?

import { deleteRoom } from './deleteRoom';

Cypress.addDualCommand('deleteRoom', deleteRoom);

Just a recommendation! :)



This comment has been minimized.


jennifer-shehane commented Sep 6, 2017

The code for this is done, but this has yet to be released. We'll update this issue and reference the changelog when it's released.


This comment has been minimized.


brian-mann commented Sep 14, 2017

Fixed in 0.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment