我有以下测试:import { throttle } from "./event";jest.useFakeTimers();it('mock setTimeout test', () => { const mockedFunction = jest.fn(); throttle(mockedFunction, 1); expect(setTimeout).toHaveBeenLastCalledWith(mockedFunction, 1000); expect(setTimeout).toHaveBeenCalledTimes(1);});油门在哪里:export const throttle = (func, wait) => { let timer = null; return function(...args) { if (timer === null) { timer = setTimeout(() => { func.apply(this, args); timer = null; }, wait); } };};但测试失败:
添加回答
举报
0/150
提交
取消