Skip to content

Disallow using findBy* inside a waitFor block #910

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
neriyarden opened this issue Jun 27, 2024 · 2 comments · Fixed by #1013
Closed

Disallow using findBy* inside a waitFor block #910

neriyarden opened this issue Jun 27, 2024 · 2 comments · Fixed by #1013
Labels
enhancement New feature or request released

Comments

@neriyarden
Copy link
Contributor

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

@neriyarden neriyarden added new rule New rule to be included in the plugin triage Pending to be triaged by a maintainer labels Jun 27, 2024
@Belco90
Copy link
Member

Belco90 commented Jun 27, 2024

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.

@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Jun 27, 2024
@Belco90 Belco90 added enhancement New feature or request and removed new rule New rule to be included in the plugin labels May 29, 2025
Copy link

🎉 This issue has been resolved in version 7.3.0 🎉

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
enhancement New feature or request released
Projects
None yet
2 participants