Skip to content
Permalink
Browse files

feat: Add handling for when the wait method is given an Identifier wh…

…ich has a number value
  • Loading branch information
chrisbreiding committed Dec 13, 2019
2 parents 9086352 + 0ef8935 commit e66bdfd7e18bf273f85ef000d30a80b16d5467c2
Showing with 20 additions and 2 deletions.
  1. +17 −2 lib/rules/no-unnecessary-waiting.js
  2. +3 −0 tests/lib/rules/no-unnecessary-waiting.js
@@ -21,8 +21,12 @@ module.exports = {
create (context) {
return {
CallExpression (node) {
if (isCallingCyWait(node) && isNumberArgument(node)) {
context.report({ node, messageId: 'unexpected' })
if (isCallingCyWait(node)) {
const scope = context.getScope()

if (isIdentifierNumberConstArgument(node, scope) || isNumberArgument(node)) {
context.report({ node, messageId: 'unexpected' })
}
}
},
}
@@ -42,3 +46,14 @@ function isNumberArgument (node) {
node.arguments[0].type === 'Literal' &&
typeof (node.arguments[0].value) === 'number'
}

function isIdentifierNumberConstArgument (node, scope) {
if (node.arguments[0].type !== 'Identifier') {
return false
}

const resolvedIdentifier = scope.resolve(node.arguments[0]).resolved
const IdentifierValue = resolvedIdentifier.defs[0].node.init.value

return typeof IdentifierValue === 'number'
}
@@ -18,11 +18,14 @@ ruleTester.run('no-unnecessary-waiting', rule, {
{ code: 'cy.clock(5000)', parserOptions },
{ code: 'cy.scrollTo(0, 10)', parserOptions },
{ code: 'cy.tick(500)', parserOptions },

{ code: 'const someRequest="@someRequest"; cy.wait(someRequest)', parserOptions, errors },
],

invalid: [
{ code: 'cy.wait(0)', parserOptions, errors },
{ code: 'cy.wait(100)', parserOptions, errors },
{ code: 'cy.wait(5000)', parserOptions, errors },
{ code: 'const someNumber=500; cy.wait(someNumber)', parserOptions, errors },
],
})

0 comments on commit e66bdfd

Please sign in to comment.
You can’t perform that action at this time.