-
Notifications
You must be signed in to change notification settings - Fork 233
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
waitForNextUpdate is missing updates #656
Comments
Hi @brainkim, the reason I'm assuming the reason you are not getting the discreet results is because React is not returning from If you truly want to assert in between the updates, using a promise that resolves after a short delay (e.g. |
Yes I’m in full agreement here. The transitory renders which happen within a microtask loop shouldn’t be tested, especially because React 18 doing batched renders for every update is about to break the tests of everyone who’s testing this stuff anyways. The actual reason I wanted react-hooks-testing-library to not miss updates is because of flakiness issues in the test suite, where tests would occasionally pass or fail based on which update Anyways, thanks for the library, and thanks for your response. |
|
Ah, didn’t see that. So the loop runs at the speed of |
Yep. it boils down to a race between the next render and the timeout, wrapped in |
@brainkim is there anything else to look at or talk about here or can I close this? |
So, I’m too lazy to debug it right now, but does the |
Not that I can think of. When you peal back the layers, it really isn't very clever. If you can point me to a particularly flaky test, I'm happy to dig into it for you. |
Hello, I have the same issue, or similar issue
is very flaky, I can make it about 90% flaky if I use the --runInBand flag. |
react-hooks-testing-library
version: 7.0.1react
version: 17.0.2react-dom
version (if applicable): 17.0.2react-test-renderer
version (if applicable): N/Anode
version: 14.17.3npm
(oryarn
) version: 6.14.3Relevant code or config:
What you did:
Hi, I’m currently trying to adopt testing-library/react-hooks to clean up Apollo Client’s test suite. One problem I’m having is that
waitForNextUpdate()
sometimes misses renders, especially when multiple state updates happen in additional microtasks.What happened:
waitForNextUpdate()
misses an update.Reproduction:
See the code above.
Problem description:
See above.
Suggested solution:
The
waitForNextUpdate()
function seems to callwait()
but I don’t understand why we can’t just return a promise whose resolve function is added toaddResolver()
?https://github.com/testing-library/react-hooks-testing-library/blob/main/src/core/asyncUtils.ts#L86-L98
The text was updated successfully, but these errors were encountered: