sinonjs/fake-timers

requestIdleCallback: callback's IdleDeadline API is not implemented

dvoytenko opened this issue · 4 comments

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.

  • FakeTimers version : appears to still exist at HEAD
  • Environment : any
  • Other libraries you are using: sinon

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) {
    ...
  }
})

Thanks for noting this!

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

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 ... :)

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

stale commented

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.