-
Notifications
You must be signed in to change notification settings - Fork 470
Test really slow because of MutationObserver not disconnecting directly #800
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
Comments
Hi @romain-trotard, Thanks for this! I'd love to speed this up. Here's the PR that added the If you can figure out how to avoid the problem that PR solved and make it faster, I'd welcome a PR for that. |
Hi @kentcdodds. |
I'm back, after an afternoon of investigation :) The use of Since the version I made all my tests on the https://github.com/grigasp/dom-testing-library-waitforelement-issue project and mine, with the three options presents here https://github.com/testing-library/dom-testing-library/releases/tag/v7.0.0, and did not see any problem to call both:
Like this, I guess, there is no breaking change for projects which do not use at least the version For one test suite:
For all test suites:
(I have a lot of test which are utilities tests, not using dom-testing-library) I will open a PR adding this, hoping that you do not see any problem :D |
Are we sure that this problem is still an issue ? |
Actually, the problem of the PR #102 is now present in the That's why I proposed to call both:
But if you guys think that we do not have to handle this case, we can also just replace the line. |
We can check if we are using |
Seems like the line is gonna finally be removed :D Just for your last comment, I'm interested to know how you would implement it ?
Like this? Or is there another better solution? |
I don't think it's worth the complexity. People should run their code in an environment that has proper support for MutationObserver. |
Again thank you all I close the issue :) |
@testing-library/dom
version: 7.26.3@testing-library/react
version: 11.1.0jest
version: 26.6.1jsdom
version: 16.4.0Hello guys :)
What happened:
My tests are really slow.
Reproduction:
I made a little codesandbox: https://codesandbox.io/s/mutationobserver-reproduction-pe9gf?file=/src/__tests__/index.js where you can see my problem.
The issue is that the callback of waitFor is called even when the element has been found:

The console log is printed thrice instead of one:

Problem description:
The MutationObserver is disconnected at the end of the test instead of directly when the onDone callback is called. I guess this is because the thread is not available until the end of the test.
These unnecessary callback's calls (in the MutationObserver) make my tests really slow as you can see below:
Suggested solution:
I have tested to directly disconnect the observer instead of inside the setImmediate method (https://github.com/testing-library/dom-testing-library/blob/master/src/wait-for.js#L97). I get really faster tests:
Is there a reason to disconnect the observer inside setImmediate instead of synchronously ?
Am I doing something wrong ?
Or maybe I could make a PR to make the disconnection configurable globally (choice would be between synchronously and asynchronously) ?
The text was updated successfully, but these errors were encountered: