mockaf

Mocks *AnimationFrame methods.

Usage no npm install needed!

<script type="module">
  import mockaf from 'https://cdn.skypack.dev/mockaf';
</script>

README

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