Skip to content

Commit

Permalink
fix: Add support for template literals to require-data-selectors rule
Browse files Browse the repository at this point in the history
fix: require data selectors support template literal
  • Loading branch information
chrisbreiding committed Feb 18, 2020
2 parents 61af626 + 550f377 commit 958549f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rules/require-data-selectors.js
Expand Up @@ -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-'))
)
}
2 changes: 2 additions & 0 deletions tests/lib/rules/require-data-selectors.js
Expand Up @@ -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: [
Expand All @@ -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 },
],
})

0 comments on commit 958549f

Please sign in to comment.