sinonjs / fake-timers

Fake setTimeout and friends (collectively known as "timers"). Useful in your JavaScript tests. Extracted from Sinon.JS
BSD 3-Clause "New" or "Revised" License
797 stars 104 forks source link

requestIdleCallback: callback's IdleDeadline API is not implemented #358

Open dvoytenko opened 3 years ago

dvoytenko commented 3 years ago

We understand you have a problem and are in a hurry, but please provide us with some info to make it much more likely for your issue to be understood, worked on and resolved quickly.

What did you expect to happen?

install() by default patches requestIdleCallback. But when the callback is called, it doesn't have IdleDeadline argument. It's described here. Thus a code that may use this argument will fail.

How to reproduce

Describe with code how to reproduce the faulty behaviour or link to code on JSBin or similar

A sample code is:

requestIdleCallback(function(deadline) {
  if (deadline.timeRemaining() > 0) {
    ...
  }
})
fatso83 commented 3 years ago

Thanks for noting this!

P.S. Quickest way of getting your itch scratch is scratching it yourselves. PRs welcome ;)

fatso83 commented 3 years ago

Hi, I looked into this, and found several issues.

  1. Your issue - the callback not getting the argument.
  2. The actual current implementation is wrong. It uses a number for the timeout, instad of { timeout } (an object).
  3. It does nothing with the timeout. It should schedule the timer to be called at timeout if it has not been called.

All of these are quite simple, but the third requires some effort and tests. would love a hand ... :)

fatso83 commented 1 year ago

This is actually mostly done in #421, but requires some debugging to fix the broken tests

stale[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.