False positive with `await-async-query` when followed by destructuring without declaration
See original GitHub issueHave you read the Troubleshooting section?
Yes
Plugin version
v5.6.0
ESLint version
v7.32.0
Node.js version
16.31.1
package manager and version
yarn 1.22.19
Operating system
macOS Monterey
Bug description
The rule await-async-query
identifies error when an awaited query is followed by a destructuring array without variable declaration and semicolons is disallowed.
I have this false positive when trying to fix prefer-destructuring
(rule which we have enabled) on the next line.
// ...
buttons = await screen.findAllByRole('button')
([removeButton] = buttons)
userEvent.click(removeButton)
// ...
Steps to reproduce
- Declare a variable;
- Call test-library query which returns array (findAll*) with await;
- Assign the value first returned value from de query to the previously declared variable using destructuring;
Error output/screenshots

ESLint configuration
module.exports = { parser: ‘babel-eslint’, rules: { ‘semi’: [‘error’, ‘never’], ‘prefer-destructuring’: ‘warn’, ‘testing-library/await-async-query’: ‘error’, }, plugins: [‘testing-library’], }
Rule(s) affected
- testing-library/await-async-query
- prefer-destructuring
Anything else?
No response
Do you want to submit a pull request to fix this bug?
No
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Rule await-async-query "false positive" with other findBy*s #498
Analysis for hierarchies with Call- and Memberexpressions are not correctly detected if one member identifier contains "findBy" pattern and does ...
Read more >Does desctructuring assignment not work the same with async ...
As demonstrated in the live code snippet below, the answer is yes. Destructuring assignments work on the results of awaited function calls ...
Read more >Common mistakes with React Testing Library - Kent C. Dodds
Using the wrong query · Using container to query for elements · Not querying by text · Not using *ByRole most of the...
Read more >Missing await for an async function call false positive in ...
Missing await for an async function call false positive in ternary in object property. What steps will reproduce the issue? See following code:....
Read more >Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, this was an interesting issue to look at.
This is related to how JavaScript handles automatic semicolon insertion (ASI). As described by Eslint’s
semi
rule:As the destructuring line
([removeButton] = buttons)
starts with(
, JavaScript does not insert a semicolon before it. If we would remove the brackets around the destructuring, the line would still start with[
, and there would be no semicolon either.Without the semicolon, AST sees the destructuring
([removeButton] = buttons)
as an argument to aCallExpression
. Since this kind of syntax (screen.findAllByRole('text')('somethingElse')
) is not validtesting-library
syntax, there aren’t unit tests (at least for this rule) with this syntax, and therefore this rule reports this as a false positive.@Belco90 what do you think, should the rule handle this type of edge case?
P.S. Another workaround is to declare the
removeButton
on the next line:Thanks @Belco90, A quick workaround for who is facing this issue is adding semicolon on the beginning of destructuring line. Obs: I don’t know if this workaround is going to work for any other rules combination.