Skip to content

Commit 958549f

Browse files
fix: Add support for template literals to require-data-selectors rule
fix: require data selectors support template literal
2 parents 61af626 + 550f377 commit 958549f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/rules/require-data-selectors.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ function isCallingCyGet (node) {
3939

4040
function isDataArgument (node) {
4141
return node.arguments.length > 0 &&
42-
node.arguments[0].type === 'Literal' &&
43-
String(node.arguments[0].value).startsWith('[data-')
44-
42+
(
43+
(node.arguments[0].type === 'Literal' && String(node.arguments[0].value).startsWith('[data-')) ||
44+
(node.arguments[0].type === 'TemplateLiteral' && String(node.arguments[0].quasis[0].value.cooked).startsWith('[data-'))
45+
)
4546
}

tests/lib/rules/require-data-selectors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ruleTester.run('require-data-selectors', rule, {
1515
{ code: 'cy.clock(5000)', parserOptions },
1616
{ code: 'cy.scrollTo(0, 10)', parserOptions },
1717
{ code: 'cy.tick(500)', parserOptions },
18+
{ code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions },
1819
],
1920

2021
invalid: [
@@ -23,5 +24,6 @@ ruleTester.run('require-data-selectors', rule, {
2324
{ code: 'cy.get(".btn-large").click()', parserOptions, errors },
2425
{ code: 'cy.get(".btn-.large").click()', parserOptions, errors },
2526
{ code: 'cy.get(".a")', parserOptions, errors },
27+
{ code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors },
2628
],
2729
})

0 commit comments

Comments
 (0)