Skip to content

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

Open
@zaicevas

Description

@zaicevas

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestnew ruleNew rule to be included in the pluginpinnedPinned for different reasons. Issues with this label won't be flagged as stale by stalebot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions