Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: references is not iterable / cant parse expect(findBy*)
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 committed Dec 10, 2019
commit 32ca20877589ab9f8219d4a261c345bf57fc5f51
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`,
},
],
})),
],
});