testing-library / testing-library/eslint-plugin-testing-library

New rule: force `waitForElementToBeRemoved` when `waitFor` is used to wait for disappearance

Open
#411 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement new rule pinned
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.