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

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

Open tgdevereux opened this issue 2 years ago • 6 comments

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?

tgdevereux avatar Mar 29 '23 13:03 tgdevereux

@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 [email protected] is correctly linting for the scrollIintoView() command.

Thank you for verifying!

emilyrohrbough avatar Mar 30 '23 23:03 emilyrohrbough

@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

tgdevereux avatar Mar 31 '23 13:03 tgdevereux

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

emilyrohrbough avatar Mar 31 '23 13:03 emilyrohrbough