| 1 |
const deferUntilFrame = require( '../../resources/skins.vector.js/deferUntilFrame.js' ); |
| 2 |
|
| 3 |
describe( 'deferUntilFrame.js', () => { |
| 4 |
let spy; |
| 5 |
|
| 6 |
beforeEach( () => { |
| 7 |
spy = jest.spyOn( window, 'requestAnimationFrame' ).mockImplementation( ( cb ) => { |
| 8 |
setTimeout( () => { |
| 9 |
cb( 1 ); |
| 10 |
} ); |
| 11 |
|
| 12 |
return 1; |
| 13 |
} ); |
| 14 |
} ); |
| 15 |
|
| 16 |
afterEach( () => { |
| 17 |
spy.mockRestore(); |
| 18 |
} ); |
| 19 |
|
| 20 |
it( 'does not fire rAF if `0` is passed', ( done ) => { |
| 21 |
deferUntilFrame( () => { |
| 22 |
expect( spy ).toHaveBeenCalledTimes( 0 ); |
| 23 |
done(); |
| 24 |
}, 0 ); |
| 25 |
} ); |
| 26 |
|
| 27 |
it( 'fires rAF the specified number of times', ( done ) => { |
| 28 |
deferUntilFrame( () => { |
| 29 |
expect( spy ).toHaveBeenCalledTimes( 3 ); |
| 30 |
done(); |
| 31 |
}, 3 ); |
| 32 |
} ); |
| 33 |
} ); |