Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tronguye opened this issue Feb 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@tronguye
Copy link

tronguye commented Feb 28, 2024

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

@tronguye tronguye added bug Something isn't working triage Pending to be triaged by a maintainer labels Feb 28, 2024
@Belco90
Copy link
Member

Belco90 commented 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.

@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants