Skip to content

Commit

Permalink
test: add test and fix the rule
Browse files Browse the repository at this point in the history
  • Loading branch information
maddhruv committed Feb 18, 2020
1 parent 5c4a5d5 commit 09aa541
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rules/require-data-selectors.js
Expand Up @@ -39,7 +39,7 @@ function isCallingCyGet (node) {

function isDataArgument (node) {
return node.arguments.length > 0 &&
(node.arguments[0].type === 'Literal' || node.arguments[0].type === 'TemplateLiteral') &&
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 09aa541

Please sign in to comment.