내 코드에서 fail
조건을 호출하려고합니다. 그러나 sinon.stub().throws()
메서드를 사용하면 오류가 발생합니다. 코드에서 처리 할 수 없습니다. **Sinon JS 단위 테스트에서 sinon.stub(). throws()를 처리하는 방법
login() {
let loginData = this.loginData;
return this.authService.login(loginData).then(userData => {
let msg = `${this.niceToSeeYouAgain} ${userData.email}!`;
this.userAlertsService.showSuccessToast(msg);
this.navigationService.afterLoggedIn();
//above lines are covered in test cases
}, errorInfo => {
// below line are needed to test
this.userAlertsService.showAlertToast(errorInfo);
});
}
그리고 여기 내 단위 테스트 조각입니다 : 여기 내 조각이다
it('.login() - should throw exception - in failure case', sinon.test(() => {
let errorInfo = "some error";
let stub = sinon.stub(authService, 'login').throws();
let spy1 = sinon.spy(controller.userAlertsService, 'showAlertToast');
//call function
controller.login();
// $timeout.flush();
// expect things
console.log(stub.callCount, stub.args[0]);
}));
날이 질문은 잘못된
비슷한 문제가 있었다은 동일합니다 . 스텁에서'throws' 대신'rejects'를 사용해보십시오. –