Skip to content

Commit ea8816c

Browse files
thomaslombartBelco90
authored andcommitted
fix(await-async-query): references is not iterable / cant parse expect(findBy*) (#50)
The bug was caused by the fact that when a query is wrapped into a function It is not referenced in the getDeclaredVariables call making the references equal to false. It caused the references check to be false, to enter the else statement and thus trying to iterate over a false value.
1 parent 58cae6e commit ea8816c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/rules/await-async-query.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ module.exports = {
3939
const variableDeclaratorParent = node.parent.parent;
4040

4141
const references =
42-
variableDeclaratorParent.type === 'VariableDeclarator' &&
43-
context
44-
.getDeclaredVariables(variableDeclaratorParent)[0]
45-
.references.slice(1);
42+
(variableDeclaratorParent.type === 'VariableDeclarator' &&
43+
context
44+
.getDeclaredVariables(variableDeclaratorParent)[0]
45+
.references.slice(1)) ||
46+
[];
4647

4748
if (
4849
references &&

tests/lib/rules/await-async-query.js

+12
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,17 @@ ruleTester.run('await-async-query', rule, {
149149
},
150150
],
151151
})),
152+
...ASYNC_QUERIES_COMBINATIONS.map(query => ({
153+
code: `async () => {
154+
expect(${query}('foo')).toBeInTheDocument()
155+
}
156+
`,
157+
errors: [
158+
{
159+
line: 2,
160+
message: `\`${query}\` must have \`await\` operator`,
161+
},
162+
],
163+
})),
152164
],
153165
});

0 commit comments

Comments
 (0)