Skip to content
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

Custom command recipe throws an error #764

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/fundamentals__add-custom-command/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ You write Cypress custom command, for example for selecting DOM elements by `dat
*
* @example cy.dataCy('greeting')
*/
Cypress.Commands.add('dataCy', (value) => cy.get(`[data-cy=${value}]`))
Cypress.Commands.add('dataCy', (value) => {
cy.get(`[data-cy=${value}]`)
})
Comment on lines +14 to +16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks command chaining. The command needs to return the cy.get() chain. Either keep the original one-liner:

Cypress.Commands.add('dataCy', (value) => cy.get(`[data-cy=${value}]`))

Or explicitly return the chain:

Cypress.Commands.add('dataCy', (value) => {
  return cy.get(`[data-cy=${value}]`)
})

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

```

Yet, TypeScript compiler and IntelliSense do not understand that you have added a new method to the global `cy` object.
Expand Down