// module1.js
export function a() {
yield 1;
yield 2;
// blabla...
}
// module2.js
export function b() {
dispatch(createActionForA()); // redux 发送一个消息,redux-saga 会把这个消息转到对应的 saga 函数,比如 a()。
}
然后
// test.js
jest.mock("../../saga/moduel1", () => {
const actual = jest.requireActual("../../saga/module1");
return {
...actual,
a: jest.fn() // 这样写是不能工作的
})
};
});
但,现在,我在测试 b 的时候,我想把 a mock 掉。上面这个方法,我用来 mock 一般的 module,都能够正常工作。但 generator 不行。
请教一下大神,有没有好的方法?
另,我也想过,监听或者 mock redux 里面的 action 和 action 方法貌似也不方便。