Skip to content

Commit

Permalink
fix(await-async-query): references is not iterable / cant parse expec…
Browse files Browse the repository at this point in the history
…t(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.
  • Loading branch information
Thomas Lombart authored and Belco90 committed Dec 10, 2019
1 parent 58cae6e commit ea8816c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rules/await-async-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ module.exports = {
const variableDeclaratorParent = node.parent.parent;

const references =
variableDeclaratorParent.type === 'VariableDeclarator' &&
context
.getDeclaredVariables(variableDeclaratorParent)[0]
.references.slice(1);
(variableDeclaratorParent.type === 'VariableDeclarator' &&
context
.getDeclaredVariables(variableDeclaratorParent)[0]
.references.slice(1)) ||
[];

if (
references &&
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/await-async-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,17 @@ ruleTester.run('await-async-query', rule, {
},
],
})),
...ASYNC_QUERIES_COMBINATIONS.map(query => ({
code: `async () => {
expect(${query}('foo')).toBeInTheDocument()
}
`,
errors: [
{
line: 2,
message: `\`${query}\` must have \`await\` operator`,
},
],
})),
],
});

0 comments on commit ea8816c

Please sign in to comment.