-
Notifications
You must be signed in to change notification settings - Fork 467
Open
Labels
Description
@testing-library/domversion: 8.11.2- Testing Framework and version: [email protected]
- DOM Environment: [email protected]
Relevant code or config:
await waitForElementToBeRemoved(screen.getByText("Loading"));What you did:
Executed test
What happened:
Test fails with error Timed out in waitForElementToBeRemoved.
Reproduction:
Not sure how to dependably repro it, but when it occurs it seems to occur deterministically.
Problem description:
- Times out because
parent.contains(element)always returnstrue. - However, while debugging, I found that
document.contains(element)anddocument.contains(parent)both return false. - In other words,
parenthas been removed from the document, butdom-testing-librarydoesn't check against that. - When this occurs, I can see that
parentis of typeHTMLDivElement. I would have expected it to beHTMLHtmlElementbecause of thiswhileloop. Could it be that we have a race condition in which the element gets removed from the document prior to (or even during!) the execution of thewhileloop?
Suggested solution:
Just check if document.contains(element) rather than capturing the parent in the first place (of course, I assume there is a reason for not taking this simple approach).
SimonDrouin, ValentinH, Marcosld, ignas-sedunovas and nrcdvyskrebets