Skip to content

Rule /require-data-selectors should not warn on cy.get(selector) #270

@ana-moraes

Description

@ana-moraes

Hello,

This issue was discussed before on #44, where judemorrissey reported the warnings being applied on aliases. This part seems to be working fine, but the situation described by SeanPercy and morficus is still ongoing.

For example:

// This works
cy.get('[data-test=a]').as('a'); 
cy.get('@a'); 

// This gives a warning
const ASSESSMENT_SUBMIT = '[data-cy=assessment-submit]';
cy.get(ASSESSMENT_SUBMIT).click();

This also gives a waning when using separate files for selectors

// selectors.js

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

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

Is it possible to change the rule to accommodate this type of situation?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions