Skip to content

prefer-find-by reports querySelector #501

Closed
@zaicevas

Description

@zaicevas

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingreleased

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions