Skip to content

tanem/mockaf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mockaf

Mocks *AnimationFrame methods.

browser support NPM version

Motivation

When unit testing, it can sometimes be useful to mock the *AnimationFrame methods if the code under test makes use of them. Using mockaf allows us to execute *AnimationFrame callbacks in the same tick of the event loop, making the tests a little easier to write.

Installation

$ npm install mockaf

Example

var mockaf = require('mockaf');

// Mock all window *AnimationFrame methods.
mockaf.install();

// Schedule stuff.
window.requestAnimationFrame(function(){
  // ...
});

// Schedule more stuff.
var id = window.requestAnimationFrame(function(){
  // ...
});

// Cancel the last callback.
window.cancelAnimationFrame(id);

// Execute any callbacks stored since the last tick.
mockaf.tick();

// Restore original window.*AnimationFrame methods.
mockaf.uninstall();

API

var mockaf = require('mockaf');

mockaf.install()

Install mock implementations of all *AnimationFrame methods available on the window object.

mockaf.tick()

Execute any callbacks stored via the mocked *AnimationFrame methods since the last tick.

mockaf.uninstall()

Restore original *AnimationFrame methods on the window object.

Tests

$ npm test

Credits

License

MIT

About

👺 Mocks *AnimationFrame methods.

Resources

License

Stars

Watchers

Forks

Packages

No packages published