mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-27 17:10:19 +00:00
c3e57e0ecd
With T178356 ES6 is the default, so these can now be managed in the same module. Keeping them in the same module will hopefully allow us to make more optimizations on the long term. Change-Id: I3fe9e50143b85b4cdc3d9171a60c3720a7c26b4b
34 lines
723 B
JavaScript
34 lines
723 B
JavaScript
const deferUntilFrame = require( '../../resources/skins.vector.js/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 );
|
|
} );
|
|
} );
|