Skip to content

testing-library/await-async-queries false positives with optional chaining ?. #882

Closed
@tronguye

Description

@tronguye

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

  1. Go to a test file
  2. Add code like
it('...', async () => {
  let renderResult: RenderResult | undefined;
  renderResult = render(<div>text</div>);
   
  expect(await renderResult?.findByText('text')).toBeDefined();
));
  1. 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

added
bugSomething isn't working
triagePending to be triaged by a maintainer
on Feb 28, 2024
Belco90

Belco90 commented on Mar 4, 2024

@Belco90
Member

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.

removed
triagePending to be triaged by a maintainer
on Mar 4, 2024
added a commit that references this issue on May 15, 2025
097705f
added a commit that references this issue on May 19, 2025
e9f8f4f
github-actions

github-actions commented on May 19, 2025

@github-actions

🎉 This issue has been resolved in version 7.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @Belco90@tronguye

      Issue actions

        `testing-library/await-async-queries` false positives with optional chaining `?.` · Issue #882 · testing-library/eslint-plugin-testing-library