Skip to content

Commit 09aa541

Browse files
committed
test: add test and fix the rule
1 parent 5c4a5d5 commit 09aa541

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/rules/require-data-selectors.js

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

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

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)