Skip to content

[prefer-find-by] When query methods come from destructuring, findBy* might not be defined #167

Closed
@gndelia

Description

@gndelia

Example code before running the linter

const { getByText } = render(<Foo />)
await waitFor(() => getByText('foo'))

After automatically fixing this, the code looks like this

const { getByText } = render(<Foo />)
await findByText('foo')

There are a couple of issues:

  1. As the title mentions, findByText is not defined. If the code was using screen or any similar wrapper, instead of the bound function directly, this is not a problem.
  2. If getByText is not used elsewhere, it becomes unused, causing another error in the linter that wasn't there before - we've introduced this error
  3. Something similar might happen with waitFor - it might now be unused as well

We should definitely fix 1. as it otherwise it's a broken code. I guess I could track where getByText was defined, and add the findBy* function there.

Thoughts on 2. and 3 ?

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