1
我有一個傳奇如何使用API調用測試傳奇?
export function* mysaga(api, action) {
const response = yield call(api.service, action);
yield put(NavActions.goTo('Page', { success: response.ok }));
}
這調用API,並返回值導航到通過API調用的結果(response.ok
)另一個屏幕。
it('test',() => {
// ...
const gen = mysaga(api, action);
const step =() => gen.next().value;
// doesn't actually run the api
const response = call(api.service, {});
expect(step()).toMatchObject(response); // ok
// error, Cannot read property 'ok' of undefined
expect(step()).toMatchObject(
put(NavActions.goTo('Page', { success: response.ok }))
);
});
因爲它不是實際運行的API調用response
沒有得到確定。
我不知道該怎麼做才能測試這種情況。
我如何測試我的傳奇的第二步?