cypress-io / cypress-documentation

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

unsafe-to-chain-command error thrown when chaining should() command to scrollIntoView #5160

Open tgdevereux opened 1 year ago

tgdevereux commented 1 year ago

In the latest version of eslint-plugin-cypress, version 2.13.2, cypress/unsafe-to-chain-command lint errors appear to be getting thrown for scrollIntoView commands, when 'should' test validations are chained to the command, i.e. cy.get('button#checkout').scrollIntoView().should('be.visible')

In the Cypress docs, it lists this type of verification as correct/safe usage of the scrollIntoView command, i.e. https://github.com/cypress-io/cypress-documentation/blob/main/docs/api/actions/scrollintoview.mdx#scrolling

Is this unexpected behavior in the latest eslint-plugin-cypress version?

emilyrohrbough commented 1 year ago

@tgdevereux I re-read the documentation you linked (updated with a recent doc re-organization change- live here) and it mentions in two places that the .scrollIntoView() command is unsafe to chain further.

It appears that eslint-plugin-cypress@2.13.2 is correctly linting for the scrollIintoView() command.

Thank you for verifying!

tgdevereux commented 1 year ago

@emilyrohrbough The Cypress docs you linked appears to suggest that chaining a ".should()" verification to a .scrollIntoView() command is correct usage, via the example they give here: https://docs.cypress.io/api/commands/scrollIntoView#Scrolling This is the scrolling example listed: cy.get('button#checkout').scrollIntoView().should('be.visible')

That example seems to suggest thats correct usage, does that constitute a ' command that relies on the subject after'? The scrollIntoView() command wouldn't really be useful if it couldn't be used in a test command like that

emilyrohrbough commented 1 year ago

@tgdevereux I see, I was looking specifically at the sections that call out It is [unsafe](https://docs.cypress.io/guides/core-concepts/retry-ability#Only-queries-are-retried) to chain further commands that rely on the subject after .scrollIntoView()..

This example needs updated.