angular – ‘expect’用于没有当前规格的情况
发布时间:2020-12-17 17:32:19 所属栏目:安全 来源:网络整理
导读:我正在学习Angular 2测试,我收到一个目前对我没有意义的错误. 当没有当前规格时,使用’expect’, 测试: import {ExperimentsComponent} from "./experiments.component";import {StateService} from "../common/state.service";import {ExperimentsService}
我正在学习Angular 2测试,我收到一个目前对我没有意义的错误.
当没有当前规格时,使用’expect’, 测试: import {ExperimentsComponent} from "./experiments.component"; import {StateService} from "../common/state.service"; import {ExperimentsService} from "../common/experiments.service"; describe('experiments.component title and body should be correct',() => { let stateService = StateService; let experimentService = ExperimentsService; let app = new ExperimentsComponent(new stateService,new experimentService); expect(app.title).toBe('Experiments Page'); expect(app.body).toBe('This is the about experiments body'); }); 组件: import {Component,OnInit} from "@angular/core"; import {Experiment} from "../common/experiment.model"; import {ExperimentsService} from "../common/experiments.service"; import {StateService} from "../common/state.service"; @Component({ selector: 'experiments',template: require('./experiments.component.html'),}) export class ExperimentsComponent implements OnInit { title: string = 'Experiments Page'; body: string = 'This is the about experiments body'; message: string; experiments: Experiment[]; constructor(private _stateService: StateService,private _experimentsService: ExperimentsService) { } ngOnInit() { this.experiments = this._experimentsService.getExperiments(); this.message = this._stateService.getMessage(); } updateMessage(m: string): void { this._stateService.setMessage(m); } } 最终我想测试练习应用程序中的所有功能.但截至目前,我只是通过angular-cli生成的测试通过. 从我从文档中读到的内容看起来我正在做的事情是正确的. 解决方法
expect()语句出现在it()语句中,如下所示:
describe('ExperimentsComponent',() => { ... it('should be created',() => { expect(component).toBeTruthy(); }); ... } 这就是错误的读取方式:
你似乎有描述和它参数混淆 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |