mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 04:58:55 +08:00
3789e0cbbb
* Affix listener bug fix + close #4755 + close #4760 + clearScrollEventListeners before setTargetEventListeners + add tests for throttle + append affix test case * genMockFn -> fn()
30 lines
718 B
JavaScript
30 lines
718 B
JavaScript
import throttleByAnimationFrame from '../throttleByAnimationFrame';
|
|
|
|
jest.useFakeTimers();
|
|
|
|
describe('Test utils function', () => {
|
|
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();
|
|
});
|
|
});
|