【发布时间】:2017-01-16 04:51:40
【问题描述】:
我试图在我的 sn-p 中调用 fail 条件。
但是当我使用sinon.stub().throws() 方法时,它会显示错误。
我无法在代码中处理它。
这是我的 sn-p:
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);
});
}
**这是我的单元测试sn-p:**
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]);
}));
请告诉我做错了什么
【问题讨论】:
标签: angularjs unit-testing ecmascript-6 sinon chai