-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
unsafe-to-chain-command error thrown when chaining should() command to scrollIntoView #5160
Comments
@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 It appears that Thank you for verifying! |
@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 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 I see, I was looking specifically at the sections that call out This example needs updated. |
Why on earth does it return |
The incorrect example has moved to https://docs.cypress.io/api/commands/scrollIntoView#Scrolling with unchanged contents: ExamplesScrollingcy.get('button#checkout').scrollIntoView().should('be.visible') It's unclear why the documentation was never corrected, although https://example.cypress.io/commands/actions shows usage without contravening the it('.scrollIntoView() - scroll an element into view', () => {
// https://on.cypress.io/scrollintoview
// normally all of these buttons are hidden,
// because they're not within
// the viewable area of their parent
// (we need to scroll to see them)
cy.get('#scroll-horizontal button')
.should('not.be.visible')
// scroll the button into view, as if the user had scrolled
cy.get('#scroll-horizontal button').scrollIntoView()
cy.get('#scroll-horizontal button')
.should('be.visible')
cy.get('#scroll-vertical button')
.should('not.be.visible')
// Cypress handles the scroll direction needed
cy.get('#scroll-vertical button').scrollIntoView()
cy.get('#scroll-vertical button')
.should('be.visible')
cy.get('#scroll-both button')
.should('not.be.visible')
// Cypress knows to scroll to the right and down
cy.get('#scroll-both button').scrollIntoView()
cy.get('#scroll-both button')
.should('be.visible')
}) |
|
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?
The text was updated successfully, but these errors were encountered: