question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mixed usage of `setTimeout` and `timers.setTimeout`

See original GitHub issue

nock/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:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Chengxuancommented, Dec 31, 2018

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.

0reactions
nockbotcommented, Aug 13, 2019

🎉 This issue has been resolved in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found