Skip to content

prefer-find-by autofix doesn't respect extra code #579

Open
@Belco90

Description

@Belco90

Plugin version

v5.3.1

ESLint version

v8.14.0

Node.js version

v16.3.0

npm/yarn version

npm v8.9.0

Operating system

macOS v12.3.1

Bug description

The autofix of the rule prefer-find-by doesn't work correctly when waitFor options are provided, or there is an assertion involved.

Steps to reproduce

  1. Providing waitFor options (✅ fixed):
    const button = await waitFor(() => screen.getByText('Count is: 0'), {
        timeout: 100,
      })
  2. There is an assertion involved
    await waitFor(() =>
        expect(
          screen.getByRole('button', { name: 'Count is: 0' }),
        ).toBeInTheDocument(),
      )

Error output/screenshots

These are fixed as:

  1. Providing waitFor options:
    const button = await screen.findByText('Count is: 0')
  2. There is an assertion involved
    await screen.findByRole('button', { name: 'Count is: 0' })

ESLint configuration

N/A

Rule(s) affected

prefer-find-by

Anything else?

They should be fixed as:

  1. Providing waitFor options:
    const button = await screen.findByText('Count is: 0', { timeout: 100 })
  2. There is an assertion involved
      expect(
        await screen.findByRole('button', { name: 'Count is: 0' }),
      ).toBeInTheDocument(),

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

Yes

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions