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

API .each / .then example fails linting cypress/unsafe-to-chain-command #246

Open
MikeMcC399 opened this issue Jan 23, 2025 · 0 comments
Open

Comments

@MikeMcC399
Copy link
Collaborator

MikeMcC399 commented Jan 23, 2025

Current behavior

The following API example for .each() as shown on the documentation site under DOM Elements

cy.get('li')
  .should('have.length', 3)
  .each(($li, index, $lis) => {
    return 'something else'
  })
  .then(($lis) => {
    expect($lis).to.have.length(3) // true
  })

fails linting with the error cypress/unsafe-to-chain-command.

Desired behavior

All examples in API > Other Commands > end > Examples showing the use of the Cypress API call .each should pass linting using the Cypress linting recommended configuration as defined by the Cypress-provided cypress-io/eslint-plugin-cypress npm module.

Test code to reproduce

git clone --branch cypress-linting-each https://github.com/MikeMcC399/cypress-test-tiny
cd cypress-test-tiny
npm ci
npm run cypress:lint

Note that the example fails when run with npx cypress run because the test page https://example.cypress.io/commands/connectors doesn't match the test, however this issue is only about linting, not about getting the test to run successfully.

Cypress Version

14.0.0

Node version

v22.13.1

Operating System

Ubuntu 24.04.1 LTS

Debug Logs

$ npm run cypress:lint

> [email protected] cypress:lint
> eslint cypress


/home/mike/github/cypress-io/cypress-test-tiny/cypress/e2e/each.cy.js
  10:5  error  It is unsafe to chain further commands that rely on the subject after this command. It is best to split the chain, chaining again from `cy.` in a next command line  cypress/unsafe-to-chain-command

✖ 1 problem (1 error, 0 warnings)

Other

eslint Version

9.18.0

eslint-plugin-cypress Version

4.1.0

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant