我想使用redux- saga -test-plan模拟外部saga的返回值。
export function* callApi(endpoint, method, params) {
let { accessToken } = yield select(authSelector);
const { apiUrl } = yield select(envSelector);
if (!accessToken) {
accessToken = yield fetchAccessToken();
}
const response = yield call(api, `${apiUrl}${endpoint}`, method, params, {
Authorization: accessToken,
});
return response;
}
// saga to be tested
function* saga1(params) {
const response = yield callApi(params); // <--- mock this value
...
}发布于 2020-01-23 19:07:13
你不需要mock saga,而是使用saga中的call。
const response = yield call(callApi, params);在测试文件中。
const generator = saga1();
expect(generator().next().value).toEqual(call(callApi, params));https://stackoverflow.com/questions/59877072
复制相似问题