Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFakeTimers doesn't fake performance.now() #803

Closed
panrafal opened this issue Aug 6, 2015 · 7 comments
Closed

useFakeTimers doesn't fake performance.now() #803

panrafal opened this issue Aug 6, 2015 · 7 comments

Comments

@panrafal
Copy link

panrafal commented Aug 6, 2015

As using perfomance.now() is more robust for timeouts than Date.now(), it'd be nice if creating a clock would "pause" or synchronize performance.now to provided now value and calling clock.tick would move it.

@mroderick
Copy link
Member

Why would you use Date.now() or performance.now for setTimeout?

Can you give a usage example?

@panrafal
Copy link
Author

@mroderick "for timeouts" I've meant when you check if enough time has passed:

var started = performance.now();

function calledLater() {
  if (performance.now() - started > 5000) {
    // do something
  }
}

In my use case I'm checking if some visual feedback was visible to the user long enough before removing it. Performance.now() guarantees it'll only go forward and it's not possible to break it by adjusting the system clock.

I've fixed this for myself by stubbing performance.now() with Date.now() sinon.stub(performance, 'now', Date.now)

Since posting this I've found that timers are handled by lolex, so probably it's better to move this issue there?

@mroderick
Copy link
Member

Why not just use setTimeout?

setTimeout(function calledLater(){
    // do something
}, 5000);

@panrafal
Copy link
Author

It's not an operation that should be run after some time, but a check if sufficient amount of time has passed.

@mroderick
Copy link
Member

It's not an operation that should be run after some time, but a check if sufficient amount of time has passed.

setTimeout guarantees that sufficient time has passed, that's what it's for ...

@mroderick
Copy link
Member

In any case, pull requests to lolex would be most welcome

@mroderick
Copy link
Member

I am closing the issue here. If you feel like contributing to lolex, please open a pull request in that repository.

jcass77 referenced this issue in adamcik/media-progress-timer Apr 6, 2016
thijstriemstra added a commit to thijstriemstra/video.js that referenced this issue Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants