-
Notifications
You must be signed in to change notification settings - Fork 470
fix: Stop calling waitFor
callback after timeout
#1271
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
Merged
eps1lon
merged 7 commits into
testing-library:main
from
KevinBon:fix-waitfor-callback-leak
Jan 8, 2024
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a0bb005
prevent waitFor callback racing condition
KevinBonHubspot 6b41483
change logic
KevinBonHubspot 55ff2f2
adapt the waitFor resolve test to make it more readable
KevinBonHubspot 67793f8
surface `timeout` + waitFor `callback` calls
KevinBonHubspot 86c5c08
adding comment
KevinBonHubspot ce11c0f
adding reproductible test
KevinBonHubspot 10a1ac7
robuster assertion for not calling callback again
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this factoring, I wonder if we could simplify further by moving
checkCallback
before theadvanceTimers
. That way the loop condition makes sure we exit as soon as we'refinished
. And we can remove anothercheckCallback
on L54.At this point I would remove the "It's really important that checkCallback [...]" comment. We might have fixed the issue along the way. And since I'd rather ship this with the next major, we have a good opportunity to resurface the bug so that we can at least link a repro. It doesn't have to be a Jest test but somehow the reordering fixed "something". That "something" needs to be linked a t least. Doesn't need to be an automated test but it needs to be something. Otherwise we're chasing ghosts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move
checkCallback
before theadvanceTimers
, thewaitFor
callback
will be called twice before we advance the clock, instead of once right now.Which will break this fix: https://github.com/testing-library/dom-testing-library/pull/1073/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but not if we remove the
checkCallback
call earlier from L54, no?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be a change of behavior in
dom-testing-library/src/__tests__/fake-timers.js
Line 43 in 37ccada
timeout
smaller than theinterval
, it will instead be rejected with[Error: Timed out in waitFor.]