0
我是角度測試新手,我想對下面的例子做測試用例。請解釋我如何通過使用karma或jasmine來爲這個登錄函數編寫測試用例?角度測試用例
ngOnInit() {
// reset login status
this.authenticationService.logout();
// get return url from route parameters or default to '/'
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
}
login() {
this.loading = true;
this.authenticationService.login(this.model.username,
this.model.password)
.subscribe(
data => {this.router.navigate([this.returnUrl]);
},
error => {
this.alertService.error(error);
this.loading = false;
});
}
看看這個討論:[Angular 2 Jasmine如何測試一個組件的功能](https://stackoverflow.com/questions/40915547/angular-2-jasmine-how-to-test-a-function組件) –