1

我遇到了我们使用 lodash 的油门来避免不必要的函数调用的功能,如下所示。

export const helperFn = throttle((args) => console.log(args), 1000)

我想模拟lodash的油门功能。模拟节流 fn 的最佳方法是什么。

4

1 回答 1

0

这已经有一段时间没有答案了,所以你现在可能已经有了解决方案。但是对于后来出现的人来说,一个可行的解决方案是使用 jestsmock函数让油门简单地返回传入的方法。例如:

jest.mock("lodash/throttle", () => {
  return fn => fn;
});
于 2021-03-16T11:37:49.440 回答