Mocks *AnimationFrame methods.
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.
$ npm install mockaf
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();
var mockaf = require('mockaf');
Install mock implementations of all *AnimationFrame methods available on the window object.
Execute any callbacks stored via the mocked *AnimationFrame methods since the last tick.
Restore original *AnimationFrame methods on the window object.
$ npm test
MIT