File "Throttle.test.ts"
Full path: /home/fsibplc/public_html/sommilito-bank2/splide-4.1.3/src/js/constructors/Throttle/test/Throttle.test.ts
File
size: 880 B (880 B bytes)
MIME-type: text/x-java
Charset: utf-8
Download Open Edit Advanced Editor Back
import { Throttle } from '../Throttle';
describe( 'Throttle', () => {
test( 'can control how often the callback function should be executed by the specified duration.', done => {
const callback = jest.fn();
const duration = 1000;
const throttled = Throttle( callback, duration );
throttled();
throttled();
throttled();
throttled();
expect( callback ).toHaveBeenCalledTimes( 0 );
// In the half way of the interval.
setTimeout( () => {
throttled();
throttled();
throttled();
throttled();
expect( callback ).toHaveBeenCalledTimes( 0 );
}, duration / 2 );
// After the interval duration.
setTimeout( () => {
throttled();
throttled();
throttled();
throttled();
expect( callback ).toHaveBeenCalledTimes( 1 );
done();
}, duration + 100 );
} );
} );