-
Notifications
You must be signed in to change notification settings - Fork 93
Description
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 ! :)