Sinon fails to uninstall clock when using jest.fakeTimers()
See original GitHub issueI am using both Sinon clock and jest.useFakeTimers
for legacy reasons, and I am getting an error while trying to uninstall sinon clock: TypeError: _global.setInterval is not a function
after enabling jest.useFakeTimers()
during some test.
I know that it’s a bit fucked up to use both sinon and jest.useFakeTimers, but anyways I think that sinon should handle this situation gracefully.
- FakeTimers version : 8.1.0
- Environment : node
- Example URL :
- Other libraries you are using: React native testing library, jest
What did you expect to happen? Sinon should be able to uninstall clock even after using jest.fakeTimers What actually happens Sinon throws exception when trying to uninstall clock after using jest.fakeTimers How to reproduce
- install sinon clock:
clock = FakeTimers.install({
shouldAdvanceTime: true,
});
- use
jest.fakeTimers()
- try to uninstall clock.
- TypeError: _global.setInterval is not a function
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Timeout when using jest "useFakeTimers" functionality #2200
When mocking timers in jest I would expect mocks to pass properly as those (to ... Remove fake timers and the test case...
Read more >Timer Mocks - Jest
In the following example we enable fake timers by calling jest.useFakeTimers() . This is replacing the original implementation of ...
Read more >Sinon fake timers and syncing ticks with unpredictable timers ...
The test calls foo and then advances the clock by 20 seconds to trigger the timer, but most of the time it will...
Read more >When using Sinon's useFakeTimers, access the real time and ...
I'm using Sinon's useFakeTimers to test a time-dependent module. When in "fake time" mode, I need to use the real setTimeout, meaning that...
Read more >Using Fake Timers | Testing Library
When using fake timers in your tests, all of the code inside your ... Running all pending timers and switching to real timers...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
26 (by default) uses its own implementation and the one using Lolex is opt-in via
jest.useFakeTimere('modern')
. In v27 “modern” is the default. Might also be a mismatch in version of Lolex of courseNote that Jest ships with
@sinonjs/fake-timers
if you use “modern” fake timers (default in v27), and mixing them is not supported. You should use one or the other.