A simple mock for requestAnimationFrame testing with fake timers and request IDs.
Last updated 7 years ago .
· Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mockraf 
SYNC missed versions from official npm registry.


A simple mock for requestAnimationFrame testing with fake timers. This is a fork of the mock-raf package provided by Alex Lande which can be found here. This fork implements request IDs, which can be used e.g. to test if the right animation frames are cancelled.

Basic Usage

var createMockRaf = require('mock-raf');
var mockRaf = createMockRaf();

// Stub out your `requestAnimationFrame` method
sinon.stub(window, 'requestAnimationFrame', mockRaf.raf);

// Take 10 `requestAnimationFrame` steps (your callback will fire 10 times)



Creates a mockRaf instance, exposing the functions you'll use to interact with the mock.


  • 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 or a polyfill when using requestAnimationFrame with timers.


Replacement for requestAnimationFrame or a polyfill. Adds a callback to be fired on the next step and returns an id which may be used with cancel().


Replacement for cancelAnimationFrame or a polyfill. If provided with an id, it removes the requestAnimationFrame callback associated with this id if it exists.

If no argument is provided, all queued requestAnimationFrame callbacks are removed.


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.

Current Tags

  • 0.1.1                                ...           latest (7 years ago)

2 Versions

  • 0.1.0                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
Maintainers (1)
Dependencies (1)
Dev Dependencies (2)

Copyright © | 浙ICP备15033595号-63 |