mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 03:01:16 +00:00
23 lines
457 B
TypeScript
23 lines
457 B
TypeScript
import '../../fixtures/disable-raf';
|
|
import { throttle } from '../../../src/builtin-simulator/utils/throttle';
|
|
|
|
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
const cb = jest.fn();
|
|
|
|
describe('throttle', () => {
|
|
it('simple', async () => {
|
|
const fn = throttle(cb, 1000);
|
|
fn();
|
|
|
|
expect(cb).toBeCalledTimes(1);
|
|
|
|
await delay(200);
|
|
fn();
|
|
|
|
await delay(400);
|
|
fn();
|
|
expect(cb).toBeCalledTimes(1);
|
|
});
|
|
});
|