waitForElementToBeRemoved error reporting improvement
See original GitHub issueDescribe the feature youād like:
render(<Component/>);
await waitForElementToBeRemoved(await findByRole('spinbutton'));
const button = await findByRole('button', { name: 'Hey' });
expect(button).toBeInTheDocument();
in case there are two āspinbuttonā roles rendered at the same time in Component - the error message in the terminal will not be the usual
Found multiple elements with the role āsomeroleā and name āsomenameā (If this is intentional, then use the
*AllBy*
variant of the query (likequeryAllByText
,getAllByText
, orfindAllByText
))
instead all that is logged in the terminal is
Timed out in waitForElementToBeRemoved.
in my opinion, it would be useful to have the same error handling for waitForElementToBeRemoved as there is with other selectors such as findByRole
Suggested implementation:
call the same error handler in case waitForElementToBeRemoved fails due to multiple hits
Describe alternatives youāve considered:
const x = await waitForElementToBeRemoved(await findByRole('spinbutton'));
expect(x).not.toBeInTheDocument()
also logged in the terminal
Timed out in waitForElementToBeRemoved.
however this setup, in my opinion, doesnāt really make much sense since waitForElementToBeRemoved implicitly checks whether an element is in the document, iād say.
Teachability, Documentation, Adoption, Migration Strategy:
I wouldnāt say this would be necessary
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
I got the same
Timed out in waitForElementToBeRemoved.
sometimes when doingawait waitForElementToBeRemoved(await screen.findByRole("status"));
. When I say sometimes, I mean that it does pass 1 time out of 10. The whole test suit normally takes 25s to pass, so I am skeptical that this is really a timeout for the failing 9/10 times.I did find a work-around that works for me (but it looks ugly):
Above workaround passes 10/10.
Extra edit: I tried the following, but it fails with the same error even to the workaround succeeds every time:
@timdeschryver , thank you for your suggestion, but it is not the test that is timing out, it is
waitForElementToBeRemoved
that is timing out. The promise fromscreen.findByRole("status")
is resolved before it is passed towaitForElementToBeRemoved
.Difference between