Skip to content

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

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

Open
zaicevas opened this issue Jul 18, 2021 · 3 comments
Labels
enhancement New feature or request new rule New rule to be included in the plugin pinned Pinned for different reasons. Issues with this label won't be flagged as stale by stalebot

Comments

@zaicevas
Copy link
Contributor

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?

@MichaelDeBoey MichaelDeBoey added enhancement New feature or request new rule New rule to be included in the plugin labels Jul 18, 2021
@Belco90
Copy link
Member

Belco90 commented Jul 18, 2021

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.

@zaicevas
Copy link
Contributor Author

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

@stale
Copy link

stale bot commented Sep 17, 2021

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.

@stale stale bot added the wontfix This will not be worked on label Sep 17, 2021
@Belco90 Belco90 added pinned Pinned for different reasons. Issues with this label won't be flagged as stale by stalebot and removed wontfix This will not be worked on labels Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule New rule to be included in the plugin pinned Pinned for different reasons. Issues with this label won't be flagged as stale by stalebot
Projects
None yet
Development

No branches or pull requests

3 participants