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: fake all supported timers by default #323
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1259,14 +1259,7 @@ function withGlobal(_global) { | |
return uninstall(clock, config); | ||
}; | ||
|
||
clock.methods = config.toFake || []; | ||
|
||
if (clock.methods.length === 0) { | ||
// do not fake nextTick by default - GitHub#126 | ||
clock.methods = keys(timers).filter(function(key) { | ||
return key !== "nextTick" && key !== "queueMicrotask"; | ||
}); | ||
} | ||
clock.methods = config.toFake || keys(timers); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another technically breaking change I guess - if people passed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think this and the other one should be a major version if we land them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can open a separate PR for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes |
||
|
||
for (i = 0, l = clock.methods.length; i < l; i++) { | ||
if (clock.methods[i] === "hrtime") { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4504,19 +4504,6 @@ describe("FakeTimers", function() { | |
assert(called); | ||
clock.uninstall(); | ||
}); | ||
|
||
it("does not install by default - GitHub#126", function(done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to change this test to assert nextTick is mocked if the behavior changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed the test above, I think that's fine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, this is fine. It's implicitly true, as the code won't work unless |
||
var clock = FakeTimers.install(); | ||
var spy = sinon.spy(clock, "nextTick"); | ||
var called = false; | ||
process.nextTick(function(value) { | ||
called = value; | ||
assert(called); | ||
assert(!spy.called); | ||
clock.uninstall(); | ||
done(); | ||
}, true); | ||
}); | ||
}); | ||
|
||
describe("requestIdleCallback", function() { | ||
|
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.
seems docs were lying 🤷
queueMicrotask
was also not mocked by default