Closed
Description
Have you read the Troubleshooting section?
Yes
Plugin version
6.2.0
ESLint version
8.45.0
Node.js version
18.16.0
package manager and version
yarn 1.22.19
Operating system
Windows 10 Enterprise version 22H2
Bug description
await renderResult?.findBy*
is reporting testing-library/await-async-queries, even though the query is in fact getting awaited
Steps to reproduce
- Go to a test file
- Add code like
it('...', async () => {
let renderResult: RenderResult | undefined;
renderResult = render(<div>text</div>);
expect(await renderResult?.findByText('text')).toBeDefined();
));
- Observe error reported on line with
expect
, when we are in fact awaiting the returned promise of findByText
Error output/screenshots
No response
ESLint configuration
{
...,
plugins: [
...,
'eslint-plugin-testing-library'
],
rules: {
...,
'testing-library/await-async-queries': 'error'
}
}
Rule(s) affected
testing-library/await-async-queries
Anything else?
No response
Do you want to submit a pull request to fix this bug?
No
Activity
Belco90 commentedon Mar 4, 2024
Thanks for reporting. Indeed, the rule doesn't take optional chaining into account properly. Bear in mind that's a really strange way of asserting if the element is present tho.
fix: `await-async-queries` has false positive with optional chaining
fix(await-async-queries): false positive with optional chaining (#1009)
github-actions commentedon May 19, 2025
🎉 This issue has been resolved in version 7.2.1 🎉
The release is available on:
Your semantic-release bot 📦🚀