Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waitForElement gets into infinite setTimeout loop #99

Closed
grigasp opened this issue Sep 14, 2018 · 2 comments
Closed

waitForElement gets into infinite setTimeout loop #99

grigasp opened this issue Sep 14, 2018 · 2 comments

Comments

@grigasp
Copy link
Contributor

grigasp commented Sep 14, 2018

  • dom-testing-library version: 3.5.1
  • node version: 8.11.2
  • npm (or yarn) 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.

@kentcdodds
Copy link
Member

I'm not certain I follow you, but if I could see the code changes you're asking for I probably would. Could you make a pull request?

@kentcdodds
Copy link
Member

🎉 This issue has been resolved in version 3.5.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants