사가에서 catch 문을 테스트 할 때 문제가 있습니다. 나는 콘솔에 출력 된 Error: error
으로 아래 테스트에서 실패하는 Mocha와 chai를 사용하고 있습니다.redux-saga에서 try-catch 테스트
saga.js
function* submitCredentials(action) {
try {
} catch(e) {
yield put({type: LOGIN_FAIL, message: e.message})
}
}
test.js
it('should catch errors',() => {
const generator = submitCredentials();
const error = new Error('error');
expect(generator.throw(error).value, put({
type: actions.LOGIN_FAIL, error
}));
});
이 기대 라인이 기대'할 필요가 없습니다 (generator.throw (오류) .value) .to.equal ((넣어 { 유형 : actions.LOGIN_FAIL, '오류' 을}));' – BarthesSimpson
또는 (유형 : actions.LOGIN_FAIL, {message : 'error'} )));) – BarthesSimpson