Skip to content

Disallow using findBy* inside a waitFor block #910

Open
@neriyarden

Description

@neriyarden

Name for new rule

no-findby-in-waitfor

Description of the new rule

This new rule should prevent the usage of a findBy* method inside a waitFor.

Testing Library feature

waitFor and findBy

Testing Library framework(s)

all

What category of rule is this?

Suggests an alternate way of doing something

Optional: other category of rule

No response

Code examples

Incorrect usage

await waitFor(() => {
  const button = await findByRole("button", { name: "Submit" });
  expect(button).toBeInTheDocument()
};

Correct usage

  const button = await findByRole("button", { name: "Submit" });
  expect(button).toBeInTheDocument()

Anything else?

No response

Do you want to submit a pull request to make the new rule?

Yes

Activity

added
new ruleNew rule to be included in the plugin
triagePending to be triaged by a maintainer
on Jun 27, 2024
Belco90

Belco90 commented on Jun 27, 2024

@Belco90
Member

Thanks for your idea! I'd update the current prefer-find-by to report this case, instead of creating a new rule. We would need to update the rule description so it indicates that suggests using findBy queries instead of waitFor + queries to wait for elements.

removed
triagePending to be triaged by a maintainer
on Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    new ruleNew rule to be included in the plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Belco90@neriyarden

        Issue actions

          Disallow using findBy* inside a waitFor block · Issue #910 · testing-library/eslint-plugin-testing-library