cypress-io / cypress-documentation

Cypress Documentation including Guides, API, Plugins, Examples, & FAQ.
https://docs.cypress.io
MIT License
938 stars 1.04k forks source link

'unsafe-to-chain-command' has too many false positives #5216

Open microbae opened 1 year ago

microbae commented 1 year ago

Is it intended that the 'unsafe-to-chain-command' rule hits, if you use quite normal stuff like the ones given in the official Cypress documentation? I think the rule should do much more than just checking if the action is included in the unsafeToChainActions array. There are too many false positives here..

Example:

See https://docs.cypress.io/api/commands/blur cy.get('[name="comment"]').focus().type('Nice Product!').blur()

nagash77 commented 1 year ago

@microbae Can you elaborate a bit more on why you think this is a false positive and what you think the correct behavior should be?

riboher commented 1 year ago

Hi! There are still some cases in which this eslint rule is causing an error even when the code looks exactly the same as some examples in the cypress documentation.

cy.get('.map-container').scrollIntoView().should('be.visible');

This is causing an error and it's something that is widely used and showed in the cypress docs

mjhenkes commented 1 year ago

@riboher as i understand it from here: https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle

That command should be broken up where you end chains after an action.

cy.get('.map-container').scrollIntoView();
cy.get('.map-container').should('be.visible');

I think the blur command should be broken up too.

cy.get('[name="comment"]').focus().type('Nice Product!')
cy.get('[name="comment"]').blur()

So it seems like the cypress docs need to be updated.

mschile commented 1 year ago

Transferred this issue to the cypress-documentation repo so the documentation examples can be updated.

alex-w0 commented 1 year ago

I experienced the same issue with cy.focused().blur() and I don't think this should be split up.

tonai commented 1 year ago

Same for me, I have an eslint error on the following line:

cy.focused().should('have.id', 'name');

I don't think I can split this.

dominicfraser commented 1 year ago

For

cy.focused().should('have.id', 'name');

the docs explicitly say this is safe, but it does flag on cypress/unsafe-to-chain-command in eslint-plugin-cypress 2.14.0

https://docs.cypress.io/api/commands/focused#Syntax

cy.focused() is a query, and it is safe to chain further commands.

I've made a PR here: https://github.com/cypress-io/eslint-plugin-cypress/pull/142

MikeMcC399 commented 12 months ago