I have a saga
export function* mysaga(api, action) {
const response = yield call(api.service, action);
yield put(NavActions.goTo('Page', { success: response.ok }));
}
That calls an API and with return value navigate to another screen passing the API call result (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 }))
);
});
Since it's not actually running the API call response
doesn't get defined.
I don't know what I should do to test this scenario.
How do I test the second step of my saga?