【问题标题】:Test cases in angular角度测试用例
【发布时间】:2017-09-15 09:10:37
【问题描述】:

我是 Angular 新手,我想对下面的示例做测试用例。请解释一下如何使用 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;
                        });
            }

【问题讨论】:

标签: angularjs jasmine karma-jasmine


【解决方案1】:

要在 Angular 中编写测试用例,您需要执行以下操作:

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

2.8是最新的茉莉版本

【讨论】:

  • 我已经完成了安装过程。现在我必须为该登录功能编写测试用例..建议我举几个例子......为此。
猜你喜欢
  • 1970-01-01
  • 2013-10-12
  • 2016-10-03
  • 2019-03-13
  • 1970-01-01
  • 2019-02-15
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
相关资源
最近更新 更多