Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mock-raf

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-raf

A simple mock for requestAnimationFrame testing with fake timers.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
increased by7.03%
Maintainers
1
Weekly downloads
 
Created
Source

mock-raf

A simple mock for requestAnimationFrame testing with fake timers.

Adapted with gratitude from react-motion. Original source here.

Basic Usage

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 });

API

createMockRaf()

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

Returns:

  • now()
  • raf()
  • cancel()
  • step()
var mockRaf = createMockRaf();

now()

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.

raf()

Replacement for requestAnimationFrame or a polyfill. Adds a callback to be fired on the next step.

cancel()

Replacement for cancelAnimationFrame or a polyfill. Removes all currently scheduled requestAnimationFrame callbacks from the queue.

step(options)

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.

Options

step() takes an optional options object:

time

Type: Number Default: 1000 / 60

The time that should pass during each requestAnimationFrame step in milliseconds. Default is roughly equivalent to default browser behavior.

count

Type: Number Default: 1

The number of steps to take.

FAQs

Package last updated on 08 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc