2023-04-10 19:31:50 +00:00
|
|
|
const deferUntilFrame = require( '../../resources/skins.vector.js/deferUntilFrame.js' );
|
2022-02-08 21:14:33 +00:00
|
|
|
|
|
|
|
describe( 'deferUntilFrame.js', () => {
|
|
|
|
let /** @type {jest.SpyInstance} */ spy;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
|
|
spy = jest.spyOn( window, 'requestAnimationFrame' ).mockImplementation( ( cb ) => {
|
|
|
|
setTimeout( () => {
|
|
|
|
cb( 1 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
afterEach( () => {
|
|
|
|
spy.mockRestore();
|
|
|
|
} );
|
|
|
|
|
2023-04-10 20:56:58 +00:00
|
|
|
it( 'does not fire rAF if `0` is passed', ( done ) => {
|
2022-02-08 21:14:33 +00:00
|
|
|
deferUntilFrame( () => {
|
|
|
|
expect( spy ).toHaveBeenCalledTimes( 0 );
|
|
|
|
done();
|
|
|
|
}, 0 );
|
|
|
|
} );
|
|
|
|
|
2023-04-10 20:56:58 +00:00
|
|
|
it( 'fires rAF the specified number of times', ( done ) => {
|
2022-02-08 21:14:33 +00:00
|
|
|
deferUntilFrame( () => {
|
|
|
|
expect( spy ).toHaveBeenCalledTimes( 3 );
|
|
|
|
done();
|
|
|
|
}, 3 );
|
|
|
|
} );
|
|
|
|
} );
|