Open
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?