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.

Missing information in documentation about shouldAdvanceTime

See original GitHub issue
  • FakeTimers version : 6.0.1

I am using fake-timers for some time now and I wanted to utilize the shouldAdvanceTime option. But I did not get it to work from the start.

This was my install code;

const installFakeClock = (): void => {
  (window as any).fakeClock = install({
    now: new Date(),
    toFake: ['setTimeout', 'clearTimeout'],
    shouldAdvanceTime: true,
  });
};

According to the documentation, this should work. Set shouldAdvanceTime to true and it will use the default time delta of 20ms. However, it would not work. The fake timer was not advancing automatically.

I had to look through the source to see that it actually also expects setInterval and clearInterval to be faked too.

I’m not sure why the advanceTime needs set and clearInterval to be faked too, but it was not expected. If it is needed, could you change the documentation to reflect that the setInterval and clearInterval are needed for this option to work?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
stefanschenkcommented, Jun 21, 2021

@fatso83 Thanks for looking into it and creating a PR in such short time.

1reaction
fatso83commented, Jun 21, 2021

Did not hear back, but this should make the actual implementation be in line with the docs, so no doc update needed 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Modern" fake-timer implementation doesn't work with ... - GitHub
Testing async code with Promises, as described in this Jest doc, doesn't seem to work with jest.useFakeTimers('modern'); (from #7776; documented ...
Read more >
Sinon useFakeTimers() creates a timeout in before/afterEach
Mystery solved. It appears to be a conflict between Sinon and versions of Knex > 0.7.6. Seems to be because pool2 relies on...
Read more >
@sinonjs/fake-timers | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com.
Read more >
webdriverio/webdriverio - Gitter
Hello everyone. I'm currently having a problem with the autocompletion with the browser methods (as well as not recognizing them whenver I Ctrl+click...
Read more >
Fake-timers: Fake SetTimeout, Friends (collectively Known As ...
var FakeTimers = require("@sinonjs/fake-timers"); var clock = FakeTimers.install({ shouldAdvanceTime: true, advanceTimeDelta: 40, }); setTimeout(() ...
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