![Maintenance Status][maintenance-image]
A simple mock for requestAnimationFrame
testing with fake timers.
Adapted with gratitude from react-motion
. Original source here.
var createMockRaf = require('mock-raf');
var mockRaf = createMockRaf();
// Stub out your `requestAnimationFrame` method
sinon.stub(window, 'requestAnimationFrame').callsFake(mockRaf.raf);
// Take 10 `requestAnimationFrame` steps (your callback will fire 10 times)
mockRaf.step({ count: 10 });
Creates a mockRaf
instance, exposing the functions you'll use to interact with the mock.
Returns:
- now()
- raf()
- cancel()
- step()
var mockRaf = createMockRaf();
Returns the current now
value of the mock. Starts at 0 and increases with each step()
taken. Useful for stubbing out performance.now()
or a polyfill when using requestAnimationFrame
with timers.
Replacement for requestAnimationFrame
or a polyfill. Adds a callback to be fired on the next step.
Replacement for cancelAnimationFrame
or a polyfill. Removes all currently scheduled requestAnimationFrame
callbacks from the queue.
Takes requestAnimationFrame
steps. Fires currently queued callbacks for each step and increments now
time for each step. The primary way to interact with a mockRaf
instance for testing.
step()
takes an optional options
object:
Type: Number
Default: 1000 / 60
The time that should pass during each requestAnimationFrame
step in milliseconds. Default is roughly equivalent to default browser behavior.
Type: Number
Default: 1
The number of steps to take.
Archived: This project is no longer maintained by Formidable. We are no longer responding to issues or pull requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!