【发布时间】:2020-04-02 03:07:24
【问题描述】:
我正在使用 Jest 测试 Redux 操作函数 fn1。 fn1 是包装 fn2 的高阶函数。我的测试只是为了确保在执行 fn1 时调用 fn2。似乎不起作用。我正在考虑使用jest.spyOn,但这似乎没有意义。
myActions.js:
export const fn1 = obj => {
return strInput => {
fn2(strInput, obj);
};
};
export const fn2 = (strInput, obj) => ({name:strInput, obj});
myAction.test.js:
import {fn1, fn2} from myAction.test.js
it("should call fn2", () => {
fn1({test:"test"})("David")
expect(fn2).toHaveBeenCalled();
});
【问题讨论】:
标签: reactjs testing redux jestjs higher-order-functions