testing-library / testing-library/eslint-plugin-testing-library
New rule: force `waitForElementToBeRemoved` when `waitFor` is used to wait for disappearance
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 168
- Avg merge
- 15h 44m
- Merged PRs (30d)
- 14
Description
We could have a new rule that reports waitFor in cases where waitForElementToBeRemoved could be used. Could be named prefer-waiting-for-disappearance or something similar.
From the implementational side, it'd probably make sense to look for RTL queries inside waitFor and some specific matchers, such as .not.toBeInTheDocument(), .toBeFalsy(), etc.
// BAD:
await waitFor(() =>
expect(screen.queryByText("Loading")).not.toBeInTheDocument(),
)
// GOOD
await waitForElementToBeRemoved(() => screen.queryByText("Loading"))
I am also curious about the fact that if this rule is enabled, it doesn't make too much sense to have query* queries in waitFor, even when waiting for appearance. Hence, the rule could either report by default or have an option to report this case:
await waitFor(() => expect(screen.queryByText("Loading")).toBeInTheDocument())
WDYT?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the waitFor and waitForElementToBeRemoved examples in the issue, including the suggested RTL query and matcher patterns. Define which disappearance cases must be reported and whether query* uses while waiting for appearance are included or configurable; done means the rule behavior and option scope are settled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- testing-qa, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100