Mixed usage of `setTimeout` and `timers.setTimeout`
See original GitHub issuenock/lib/request_overrider.js
uses both setTimeout
and timers.setTimeout
. Should the project use one or the other for the sake of consistency?
Using setTimeout
is nice because if a someone is mocking the clock, then nock will use a mocked clock as well. They can still do it, but have to do additional work to mock timers
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
setTimeout() - Web APIs | MDN
The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires.
Read more >JavaScript Timers - setTimeout, setInterval, clearTimeout, and ...
How to use the built-in timer functions which allow you delay your function calls.
Read more >How To Turn SetTimeout and SetInterval Into Promises
There you go! With these two functions, sleep and asyncInterval you don't have the awkward mix of timed callbacks and regular promises. I...
Read more >Jest: Timer and Promise don't work well. (setTimeout and ...
This seems to be the best answer on the topic of mixing promises with Jest fake timers, but I don't understand it at...
Read more >Scheduling: setTimeout and setInterval
A call to setTimeout returns a “timer identifier” timerId that we can use to cancel the execution. The syntax to cancel:.
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
This could have been communicated better, our tests started failing after picked up 10.0.5 because most of them use fakeTimer which didn’t impact
nock
. Now they all timing out and it took me a while to figure out why. I agree to give more control is better, but I don’t think most of existing users know it uses a separate timer due to existing behaviour. They’ll need to go through the same debugging process as I did now.Maybe update your readme with an example would help? This is a change of behaviour for all the existing tests uses fakeTimer. Those tests will start failing with no obvious error other than timing out and it would take a while to track down to the
nock
library.🎉 This issue has been resolved in version 11.0.0 🎉
The release is available on:
Your semantic-release bot 📦🚀