Skip to content

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

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?

Activity

  1. added
    enhancement
    new rule
    on Jul 18, 2021
  2. Belco90 commented on Jul 18, 2021

    @Belco90
    Member

    This is an interesting one, few comments about it.

    I think the list of "disappearance matchers" is already in the codebase, so we should aim to report that list.

    I don't think the 2nd case you exposed would be in the scope of this rule. queryBy* + presence matcher is already reported by prefer-presence-queries, and reporting waitFor + presence matcher would fit better in prefer-find-by one.

  3. zaicevas commented on Jul 19, 2021

    @zaicevas
    ContributorAuthor

    I don't think the 2nd case you exposed would be in the scope of this rule. queryBy* + presence matcher is already reported by prefer-presence-queries

    Fair point.

    reporting waitFor + presence matcher would fit better in prefer-find-by one.

    Makes sense! I created an issue for it #420

  4. stale commented on Sep 17, 2021

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  5. added
    wontfix
    on Sep 17, 2021
  6. added
    pinned
    and removed
    wontfix
    on Sep 17, 2021
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

    enhancementnew rulepinned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions