角度测试用例

时间:2017-09-15 09:10:37

标签: angularjs jasmine karma-jasmine

我是角色的新手,我想在下面的例子中做测试用例。请解释我如何使用角色中的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;
                        });
            }

1 个答案:

答案 0 :(得分:0)

要以角度编写测试用例,您需要执行以下操作:

  

安装业力和茉莉   做业力初始化   创建.spec文件   使用断言库编写期望   如需更多帮助,请访问:https://jasmine.github.io/2.8/introduction

2.8是最新的茉莉花版