-
Notifications
You must be signed in to change notification settings - Fork 467
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
fix: Only use a single clock #966
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 24f082b:
|
Codecov Report
@@ Coverage Diff @@
## main #966 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 25 -1
Lines 966 914 -52
Branches 293 282 -11
=========================================
- Hits 966 914 -52
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
I'm no expert here, but I can say that the failing tests in the ATL repository are resolved with this change (on Jest 26).
If this gets released, should we also remove the remaining deprecated methods (wait
and waitForElement
) ?
Yep, this PR already targets an alpha branch so we'll collect some more breaking changes if this gets released. |
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.
Previously the behavior of waitFor was different depending on fake or real timers which I consider problematic.
This is enough to convince me. The goal of our utilities is to be able to use the async utilities and have all the tests run the same whether the timers are faked or not. And the workaround for the old behavior is pretty sensible IMO.
This looks good to me, and I love all the code that can be removed with this change 👍
Update: I also noticed flaky test failures such as https://github.com/testing-library/dom-testing-library/runs/2727330116 (also remember one PR) and these instances are hopefully also fixed by this change |
Looks like everything's been resolved here and considering this is just going to the alpha branch I'm going to go ahead with the merge 👍 Thanks for the collaboration! |
🎉 This PR is included in version 8.0.0-alpha.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
While updating Jest to v27, I faced many broken tests where As I'm not sure when v8 will be released to the stable channel, I'm wondering if the fix to use a single clock could be back-ported to v7? Or is this fix tightly linked with the removal of |
It includes breaking changes that are not coupled with
|
BREAKING CHANGE:
waitFormDOMChange
timeout
inwaitFor(callback, { interval, timeout } )
now uses the same clock asinterval
Previously
timeout
was always using the real clock whileinterval
was using the global clock which could've been mocked out. For the old behavior I'd recommendwaitFor(callback, { interval, timeout: Number.PositiveInfinity })
and rely on your test runner to timeout considering real timers.TODO:
Number.PositiveInfinity
be the new default fortimeout
?What:
Only run with a single clock.
Closes #939
Closes #756
Closes #880
Hopefully also fixes flaky test failures such as https://github.com/testing-library/dom-testing-library/runs/2727330116
Why:
The previous approach breaks jest 27. I would also consider it suprising behavior (agreeing with Closes #880). If I pass
waitFor(callback, { interval: 50, timeout: 900 })
then I expect both times to run with the same clock. Previously the behavior ofwaitFor
was different depending on fake or real timers which I consider problematic.I also don't think we need to force the
timeout
to run with the real clock. Test runners already implement this behavior. So if people don't want thetimeout
to use the same clock asinterval
then they can usewaitFor(callback, { timeout: Number.PositiveInfinity })
.How:
Backported
f1a8a14
(#962) from #962. This ensures that the new approach works with jest 26 (this PR) and jest 27 (#962)setTimout
instead ofsetImmediate
andsetTimeout
from the real clockwaitForDOMChange
since it relied on the now removedrunWithRealTimers
Checklist:
docs site
[ ]Typescript definitions updated/cc @testing-library/all-maintainers Since this might be fairly invasive.