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

require-data-selectors rule should not apply to cy.get('@alias') #44

Closed
judemorrissey opened this issue Feb 11, 2020 · 3 comments · Fixed by #59
Closed

require-data-selectors rule should not apply to cy.get('@alias') #44

judemorrissey opened this issue Feb 11, 2020 · 3 comments · Fixed by #59
Assignees

Comments

@judemorrissey
Copy link

Hello,

I was in the midst of updating Cypress related packages, and updated this package to the latest 2.9.0 release. I also realized there's the require-data-selectors rule which I recently enabled as a warning. However, now I have a whole bunch of warnings for places where I use aliases, e.g.

cy.get('[data-test=a]').as('a'); // this is fine
cy.get('@a'); // this is a warning

Minor issue as this is a non-essential rule to us, but I thought for posterity it is worth mentioning.

@SeanPercy
Copy link

SeanPercy commented Feb 22, 2020

In my .eslintrc file the rule cypress/require-data-selectors is set to 1.
I have a list of selectors that are defined like this:

// selectors.js

const addPrefix = testId => `[data-cy=${testId}]`;
export const ASSESSMENT_SUBMIT = addPrefix('assessment-submit');

They are imported by my test files and used as followed:

// test.js
cy.get(ASSESSMENT_SUBMIT).click();

Running eslint outputs the following:

warning  use data-* attribute selectors instead of classes or tag names  cypress/require-data-selectors

This is also the case, when they are defined in the same place / file.

const ASSESSMENT_SUBMIT = '[data-cy=assessment-submit]';
cy.get(ASSESSMENT_SUBMIT).click();

@morficus
Copy link

morficus commented Apr 6, 2020

+1 to this.
I have a similar setup to what @SeanPercy explained where my selectors are external to the spec file and being imported as variables.

@chrisbreiding
Copy link
Contributor

🎉 This issue has been resolved in version 2.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

5 participants