cypress-documentation icon indicating copy to clipboard operation
cypress-documentation copied to clipboard

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

Open microbae opened this issue 2 years ago • 8 comments

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()

microbae avatar Apr 05 '23 12:04 microbae

@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?

nagash77 avatar Apr 05 '23 13:04 nagash77

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

riboher avatar Apr 19 '23 11:04 riboher

@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.

mjhenkes avatar Apr 21 '23 13:04 mjhenkes

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

mschile avatar Apr 25 '23 20:04 mschile

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

alex-w0 avatar Sep 01 '23 07:09 alex-w0

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.

tonai avatar Sep 11 '23 12:09 tonai

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

dominicfraser avatar Sep 15 '23 16:09 dominicfraser

  • [email protected] was released with some improvements
  • https://github.com/cypress-io/cypress-example-kitchensink/issues/661 is also related and needs work doing on it to ensure that the scaffolded examples in Cypress do not fail unsafe-to-chain-command

MikeMcC399 avatar Sep 26 '23 12:09 MikeMcC399