Answer the question
In order to leave comments, you need to log in
Why does undefined fall in a catch block in a saga?
Such a problem. Throws an error when testing:
TypeError: Cannot read property 'message' of undefined. Why undefined? In theory, everything seems to be so.
export function* updateUser({ payload }) {
try {
const response = yield call(api.updateUser, payload);
yield put(updateUserSuccess(response));
} catch (e) {
yield put(updateUserFailure(e.data.message)); //на эту строку ошибка падает
yield put(req.showError(e.data.message));
}
}
const gen = sagas.updateUser({ payload: 'test' });
const error = {data: {message: 'error'}}
gen.next();
expect(gen.throw(error).value).toMatchSnapshot();
expect(gen.next().value).toMatchSnapshot();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question