Using nock with sinon fake timers
See original GitHub issueThis is more of a question rather than an issue report.
When I use Sinon to fake the current date and time like so:
Sinon.useFakeTimers(new Date("2016-01-01T00:11:22+10:00").getTime());
And then I call Nock to intercept, it never registers the URL (confirmed by turning debugging on).
However if I don’t use Sinon fake timers and I use something like mockdate js, it works.
Just curious as to what is happening here.
Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Fake timers - Sinon.JS
Fake timers are synchronous implementations of setTimeout and friends that Sinon.JS can overwrite the global functions with to allow you to more easily...
Read more >Using nock with sinon fake timers - Bountysource
When I use Sinon to fake the current date and time like so: Sinon.useFakeTimers(new Date("2016-01-01T00:11:22+10:00").getTime());.
Read more >How to use Fake timers with nightwatch.js and sinon.js?
If you just want to use a fake Date, you can write it like this: clock = sinon.useFakeTimers(new Date(2015, 7, 20).getTime(), "Date").
Read more >Best Practices for Spies, Stubs and Mocks in Sinon.js
You may need to disable fake timers for async tests when using sinon.test . This is a potential source of confusion when using...
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 >
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
Having the same problem as described above. I have a method that does long polling (and uses
setTimeout
to trigger itself in time intervals). When I use sinon fake timers nock requests are not fired at all.My test code looks like this:
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!