Skip to content

prefer-find-by reports querySelector #501

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

Closed
zaicevas opened this issue Oct 19, 2021 · 3 comments · Fixed by #538
Closed

prefer-find-by reports querySelector #501

zaicevas opened this issue Oct 19, 2021 · 3 comments · Fixed by #538
Assignees
Labels
bug Something isn't working released

Comments

@zaicevas
Copy link
Contributor

Plugin version

4.12.4

ESLint version

7.24.0

Node.js version

14.16.0

npm/yarn version

6.14.11

Operating system

macOS Big Sur

Bug description

I expect this code snippet NOT to be reported. Furthermore, error message and auto-fix have undefined instead of a meaningful message/fix.

    it('renders', async () => {
      const { container } = render(<App />)

      await waitFor(() =>
        expect(container.querySelector("[data-icon-name='bookmark-filled']")).toBeInTheDocument(), // reported
      )
    })

Auto-fixed to: await container.findByundefined("[data-icon-name='bookmark-filled']")

Steps to reproduce

  1. Setup eslint-plugin-testing-library 4.12.4
  2. Enable prefer-find-by rule
  3. Create a test with the above code snippet
  4. Run eslint with --fix

Error output/screenshots

error  Prefer `findByundefined` query over using `waitFor` + `querySelector`  testing-library/prefer-find-by

ESLint configuration

    {
      files: ['*.test.ts', '*.test.tsx'],
      parser: '@typescript-eslint/parser',
      plugins: ['testing-library'],
      rules: {
        '@typescript-eslint/no-var-requires': 'off',
        'testing-library/prefer-find-by': 'error',
      },
    },

Rule(s) affected

prefer-find-by

Anything else?

No response

Do you want to submit a pull request to fix this bug?

No

@zaicevas zaicevas added the bug Something isn't working label Oct 19, 2021
@Belco90
Copy link
Member

Belco90 commented Oct 19, 2021

HI @zaicevas! Thanks for reporting. I believe this should be an easy thing to fix, but not sure why is failing tho (our internal checks are always expecting a "queryBy" prefix, not just "query").

I'll take a look after the v5 release.

@Belco90 Belco90 self-assigned this Oct 19, 2021
@bpinto
Copy link
Contributor

bpinto commented Nov 30, 2021

I have noticed the same bug when upgrading this library on our project.

bpinto added a commit to bpinto/eslint-plugin-testing-library that referenced this issue Jan 20, 2022
bpinto added a commit to bpinto/eslint-plugin-testing-library that referenced this issue Jan 20, 2022
bpinto added a commit to bpinto/eslint-plugin-testing-library that referenced this issue Jan 21, 2022
Belco90 pushed a commit that referenced this issue Jan 21, 2022
* fix(prefer-find-by): fix report with querySelector

Fix #501

* fixup! fix(prefer-find-by): fix report with querySelector
@github-actions
Copy link

🎉 This issue has been resolved in version 5.0.4 🎉

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
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants