Angularjs 无法在之后测试行。然后在sinon js单元测试中
我是Angularjs 无法在之后测试行。然后在sinon js单元测试中,angularjs,unit-testing,ecmascript-6,sinon,sinon-chai,Angularjs,Unit Testing,Ecmascript 6,Sinon,Sinon Chai,我是sinon.js,mocha,chai的新生儿。 我正试图使用上述库编写单元测试。 项目前端位于AngularJS中,并结合了ecmascript 6 从Sinonjs的文档中,我什么都不懂!这很复杂 这是我的JS代码片段: login() { let loginData = this.loginData; return this.authService.login(loginData).then(userData => { let msg = `${thi
sinon.js
,mocha
,chai
的新生儿。
我正试图使用上述库编写单元测试。
项目前端位于AngularJS
中,并结合了ecmascript 6
从Sinonjs
的文档中,我什么都不懂!这很复杂
这是我的JS代码片段:
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();
}, errorInfo => {
this.userAlertsService.showAlertToast(errorInfo);
});
}
it('.login() - should load user data and showSuccessToast and call navigationService afterLoggedIn', sinon.test(() => {
let msg = `Nice to see you again ${userData.email}!`;
let loginData ={
email: "sarfaraz@walkover.in",
password: "designer99",
remember: true
}
let stub = sinon.stub(authService, 'login').resolves(userData);
// let spy1 = sinon.spy(controller.userAlertsService, 'showSuccessToast');
//call function
controller.login();
$timeout.flush();
// expect things
expect(stub.called).to.eq(true);
// restore
stub.restore();
}));
下面是我的单元测试片段:
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();
}, errorInfo => {
this.userAlertsService.showAlertToast(errorInfo);
});
}
it('.login() - should load user data and showSuccessToast and call navigationService afterLoggedIn', sinon.test(() => {
let msg = `Nice to see you again ${userData.email}!`;
let loginData ={
email: "sarfaraz@walkover.in",
password: "designer99",
remember: true
}
let stub = sinon.stub(authService, 'login').resolves(userData);
// let spy1 = sinon.spy(controller.userAlertsService, 'showSuccessToast');
//call function
controller.login();
$timeout.flush();
// expect things
expect(stub.called).to.eq(true);
// restore
stub.restore();
}));
但不幸的是,我被绊倒了。
我的代码不会在之后运行。然后,
行
我希望它会抛出错误。因为我没有窥探用户警报服务
和导航服务
请让我知道我做错了什么