I have the following utility function that I use in all my tests:
async function waitForContentLoaded() {
await waitFor(() => {
expect(screen.queryByRole('progressbar')).not.toBeInTheDocument();
});
}
Now 2 out of 37 tests fail with the error message expected document not to contain element, found <span {...} role="progressbar" {...} />, and a stacktrace pointing to the expectation above.
Isn't waitFor() supposed to catch these errors, and then try again until it doesn't throw?
CodePudding user response:
Here's what the documentation says:
waitFormay run the callback a number of times until the timeout is reached. Note that the number of calls is constrained by thetimeoutandintervaloptions.
The default
intervalis50ms. However it will run your callback immediately before starting the intervals.
The default
timeoutis1000ms.
So, on the final invocation before the timeout value is exceeded, waitFor will reject with any exception which occurs in the callback you provide to it.
