mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
36 lines
800 B
JavaScript
36 lines
800 B
JavaScript
import throttleByAnimationFrame from '../throttleByAnimationFrame';
|
|
|
|
describe('Test utils function', () => {
|
|
beforeAll(() => {
|
|
jest.useFakeTimers();
|
|
});
|
|
|
|
afterAll(() => {
|
|
jest.useRealTimers();
|
|
});
|
|
|
|
it('throttle function should work', () => {
|
|
const callback = jest.fn();
|
|
const throttled = throttleByAnimationFrame(callback);
|
|
expect(callback).not.toBeCalled();
|
|
|
|
throttled();
|
|
throttled();
|
|
|
|
jest.runAllTimers();
|
|
expect(callback).toBeCalled();
|
|
expect(callback.mock.calls.length).toBe(1);
|
|
});
|
|
|
|
it('throttle function should be canceled', () => {
|
|
const callback = jest.fn();
|
|
const throttled = throttleByAnimationFrame(callback);
|
|
|
|
throttled();
|
|
throttled.cancel();
|
|
|
|
jest.runAllTimers();
|
|
expect(callback).not.toBeCalled();
|
|
});
|
|
});
|