diff --git a/lib/rules/require-data-selectors.js b/lib/rules/require-data-selectors.js index b8d5203e..f3f76afb 100644 --- a/lib/rules/require-data-selectors.js +++ b/lib/rules/require-data-selectors.js @@ -39,7 +39,8 @@ function isCallingCyGet (node) { function isDataArgument (node) { return node.arguments.length > 0 && - node.arguments[0].type === 'Literal' && - String(node.arguments[0].value).startsWith('[data-') - + ( + (node.arguments[0].type === 'Literal' && String(node.arguments[0].value).startsWith('[data-')) || + (node.arguments[0].type === 'TemplateLiteral' && String(node.arguments[0].quasis[0].value.cooked).startsWith('[data-')) + ) } diff --git a/tests/lib/rules/require-data-selectors.js b/tests/lib/rules/require-data-selectors.js index af123dc9..92036bb0 100644 --- a/tests/lib/rules/require-data-selectors.js +++ b/tests/lib/rules/require-data-selectors.js @@ -15,6 +15,7 @@ ruleTester.run('require-data-selectors', rule, { { code: 'cy.clock(5000)', parserOptions }, { code: 'cy.scrollTo(0, 10)', parserOptions }, { code: 'cy.tick(500)', parserOptions }, + { code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions }, ], invalid: [ @@ -23,5 +24,6 @@ ruleTester.run('require-data-selectors', rule, { { code: 'cy.get(".btn-large").click()', parserOptions, errors }, { code: 'cy.get(".btn-.large").click()', parserOptions, errors }, { code: 'cy.get(".a")', parserOptions, errors }, + { code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors }, ], })