Skip to content

Commit e66bdfd

Browse files
feat: Add handling for when the wait method is given an Identifier which has a number value
2 parents 9086352 + 0ef8935 commit e66bdfd

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/rules/no-unnecessary-waiting.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ module.exports = {
2121
create (context) {
2222
return {
2323
CallExpression (node) {
24-
if (isCallingCyWait(node) && isNumberArgument(node)) {
25-
context.report({ node, messageId: 'unexpected' })
24+
if (isCallingCyWait(node)) {
25+
const scope = context.getScope()
26+
27+
if (isIdentifierNumberConstArgument(node, scope) || isNumberArgument(node)) {
28+
context.report({ node, messageId: 'unexpected' })
29+
}
2630
}
2731
},
2832
}
@@ -42,3 +46,14 @@ function isNumberArgument (node) {
4246
node.arguments[0].type === 'Literal' &&
4347
typeof (node.arguments[0].value) === 'number'
4448
}
49+
50+
function isIdentifierNumberConstArgument (node, scope) {
51+
if (node.arguments[0].type !== 'Identifier') {
52+
return false
53+
}
54+
55+
const resolvedIdentifier = scope.resolve(node.arguments[0]).resolved
56+
const IdentifierValue = resolvedIdentifier.defs[0].node.init.value
57+
58+
return typeof IdentifierValue === 'number'
59+
}

tests/lib/rules/no-unnecessary-waiting.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ ruleTester.run('no-unnecessary-waiting', rule, {
1818
{ code: 'cy.clock(5000)', parserOptions },
1919
{ code: 'cy.scrollTo(0, 10)', parserOptions },
2020
{ code: 'cy.tick(500)', parserOptions },
21+
22+
{ code: 'const someRequest="@someRequest"; cy.wait(someRequest)', parserOptions, errors },
2123
],
2224

2325
invalid: [
2426
{ code: 'cy.wait(0)', parserOptions, errors },
2527
{ code: 'cy.wait(100)', parserOptions, errors },
2628
{ code: 'cy.wait(5000)', parserOptions, errors },
29+
{ code: 'const someNumber=500; cy.wait(someNumber)', parserOptions, errors },
2730
],
2831
})

0 commit comments

Comments
 (0)