Skip to content
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

Feature request: Allow "body" with cypress/require-data-selectors rule #77

Open
Hyzual opened this issue Feb 24, 2021 · 0 comments
Open

Comments

@Hyzual
Copy link
Contributor

Hyzual commented Feb 24, 2021

This is more of a feature request than a bug report. We use cypress/require-data-selectors in our Cypress test suite and it's helped us a lot. However, there is a case where it can be annoying.
Say you have a keyboard shortcut on the page you are testing, for example pressing "Escape" will close a modal pop-up. We'll write a cypress test like this:

cy.get("body").type("{esc}");

But this is flagged as an error by cypress/require-data-selectors. However I would argue that adding a data-selector on <body> is kind of counter-productive, as HTML spec specifies that:

In conforming documents, there is only one body element.

Since there can be only one <body> in my document, why should I identify it with another data-attribute ?
Therefore I propose to make an exception and allow cy.get("body") with this rule. Currently, we are "working around" the errors by using aliases so that the error will only have to be disabled once instead of everywhere on the page:

// eslint-disable-next-line cypress/require-data-selectors
cy.get("body").as("body");
//...
cy.get("@body"); // Aliases are allowed

What do you think about that ?
I can write a pull request for that if you agree with the proposal.

Have a nice day ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants