我正在测试saga,我被困在哪里以及如何调用模拟api,并断言它已被调用一次。当我使用mockReturnValue时如何调用模拟api?
在下面,我应该如何以及何时调用模拟api?
import { cloneableGenerator } from "redux-saga/utils";
import * as api from "../Utilities/api";
const generator = cloneableGenerator(fetchPostSaga)();
test("fetching posts successfully", () => {
const clone = generator.clone();
const posts = {};
const mock = jest.spyOn(api, "default");
const responseValue = {
data: {
tokenIsValid: true
}
};
mock.mockReturnValueOnce({ data: responseValue });
expect(clone.next().value).toEqual(call(// mock));
expect(clone.next(posts).value).toEqual(put(postsReceived(responseValue)));
expect(clone.next().done).toBe(true);
});