UNPKG

@ryusei/code

Version:

<div align="center"> <a href="https://code.ryuseijs.com"> <img alt="RyuseiCode" src="https://code.ryuseijs.com/images/svg/logo.svg" width="70"> </a>

28 lines (20 loc) 557 B
import { rafThrottle } from './rafThrottle'; describe( 'rafThrottle', () => { test( 'can throttle the function via requestAnimationFrame.', done => { const callback = jest.fn(); const throttled = rafThrottle( callback ); throttled(); throttled(); throttled(); throttled(); expect( callback ).toHaveBeenCalledTimes( 0 ); requestAnimationFrame( () => { throttled(); throttled(); throttled(); throttled(); expect( callback ).toHaveBeenCalledTimes( 1 ); done(); } ); } ); } );