-
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
test: enable modern jest timers test #938
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 51fd8e7:
|
Codecov Report
@@ Coverage Diff @@
## master #938 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 26
Lines 953 953
Branches 289 289
=========================================
Hits 953 953
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
const response = 'data' | ||
const doAsyncThing = () => | ||
new Promise(r => setTimeout(() => r(response), time)) | ||
let result | ||
doAsyncThing().then(r => (result = r)) | ||
|
||
if (advanceTimers) { | ||
jest.advanceTimersByTime(time) |
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.
Shouldn't waitFor
take care of this?
@timdeschryver I think this is fixed by #966 and #962 without needing to change these particular tests. Can we close this PR in favor of #962?
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.
Yes of course.
Thanks for getting back to this PR, because I forgot about it.
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.
Shouldn't waitFor take care of this?
It could've been a bug in waitFor
then, the reason why I added this was because the timers weren't advancing on their own. So, I thought that I had to do that manually.
What:
Explicit set jest's faker timers to
modern
.Why:
Because in Jest 26.x the default is
legacy
.https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers
How:
Changed the modern test by passing
modern
as the options.I also had to advance the timers, and had to "clear" the timers after the test.
Checklist:
docs site