mediawiki-skins-Vector/tests/jest/deferUntilFrame.test.js
Jon Robson 96baf5db50 Eslint: Modernize tests for ES6
Change-Id: I3600afd2eeacddc8e1c983eaad0a96e0755c7ba5
2023-04-11 23:18:38 +00:00

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 );
} );
} );