mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-30 18:35:44 +00:00
96baf5db50
Change-Id: I3600afd2eeacddc8e1c983eaad0a96e0755c7ba5
34 lines
724 B
JavaScript
34 lines
724 B
JavaScript
const deferUntilFrame = require( '../../resources/skins.vector.es6/deferUntilFrame.js' );
|
|
|
|
describe( 'deferUntilFrame.js', () => {
|
|
let /** @type {jest.SpyInstance} */ spy;
|
|
|
|
beforeEach( () => {
|
|
spy = jest.spyOn( window, 'requestAnimationFrame' ).mockImplementation( ( cb ) => {
|
|
setTimeout( () => {
|
|
cb( 1 );
|
|
} );
|
|
|
|
return 1;
|
|
} );
|
|
} );
|
|
|
|
afterEach( () => {
|
|
spy.mockRestore();
|
|
} );
|
|
|
|
it( 'does not fire rAF if `0` is passed', ( done ) => {
|
|
deferUntilFrame( () => {
|
|
expect( spy ).toHaveBeenCalledTimes( 0 );
|
|
done();
|
|
}, 0 );
|
|
} );
|
|
|
|
it( 'fires rAF the specified number of times', ( done ) => {
|
|
deferUntilFrame( () => {
|
|
expect( spy ).toHaveBeenCalledTimes( 3 );
|
|
done();
|
|
}, 3 );
|
|
} );
|
|
} );
|