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
没有得到确定。
我不知道该怎么做才能测试这种情况。
我如何测试我的传奇的第二步?