-
Notifications
You must be signed in to change notification settings - Fork 469
Closed
Description
dom-testing-library
version: 3.5.1node
version: 8.11.2npm
(oryarn
) version: 5.6.0
Relevant code or config:
const { waitForElement } = require("dom-testing-library");
it("shouldn't hang after succeeding", async () => {
let didMakeMutation = false;
const createElement = () => document.createElement("div");
const container = createElement();
const myCallback = () => {
return didMakeMutation;
};
const result = waitForElement(myCallback, { container });
container.appendChild(createElement());
didMakeMutation = true;
await new Promise((resolve) => setTimeout(resolve, 50));
});
What you did:
I'm trying to use waitForElement
to wait until an element is created in the dom.
What happened:
I found that my test is passing, but the test runner (mocha) doesn't exit - it gets into infinite setTimeout loop.
Reproduction:
Repo: https://github.com/grigasp/dom-testing-library-waitforelement-issue
npm install
npm run test
Problem description:
The test succeeds, but the test runner (mocha) doesn't ever exit, because waitForElement
gets into infinite setTimeout
loop.
I think the problem is that waitForElement
calls observer.disconnect()
from the onMutation()
-> onDone()
callback. MutationObserver
, after calling the onMutation()
callback, immediately recreates the listener, and then gets into the infinite setTimeout
loop.
Suggested solution:
waitForElement
should somehow call disconnect()
after MutationObserver
recreates the listener.
Metadata
Metadata
Assignees
Labels
No labels