-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
getTimerCount will not include cancelled immediates #8764
getTimerCount will not include cancelled immediates #8764
Conversation
Should cancelled immediates get removed so |
Looking through the usages, I didn't see a reason why there kept around yeah. |
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.
do you using Map
instead of Array
for this case and handle like timers
?
private _immediates!: Map<string, Tick>;
you can easy set, delete and clear but not change reference!
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.
This LGTM! Could you update the changelog as well, please? 🙂
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.
Left one comment, other than that LGTM (and changelog as Simen said)
// Callback may throw, so update the map prior calling. | ||
cancelledImmediates[String(uuid)] = true; | ||
callback.apply(null, args); | ||
if (immediates.find(x => x.uuid === uuid)) { |
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.
why do we need this if
?
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.
please refer to this comment: #8764 (comment)
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 mean, why do we have find
at all?
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.
so we don't run immediates more than once.
If it was cleared (not in the immediates
array) then it shouldn't run even if runAllImmediates
is called
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.
Right, makes sense
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.
Mostly LGTM now, just gotta make CI green :)
The CI test that fails is not using fake timers, so not sure why it's red. Will investigate... |
CI is failing, though 😢 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
In our projects we check
getTimerCount()
to know that all our timers/immediates are cleaned between tests.I noticed that the number is getting larger after each test.
It seems that
getTimerCount()
counts cancelled immediates, this PR fixes this.Test plan
added a test at
jestFakeTimers.test.ts