angular – ‘expect’用于没有当前规格的情况

前端之家收集整理的这篇文章主要介绍了angular – ‘expect’用于没有当前规格的情况前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在学习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();
  });
...
}

这就是错误的读取方式:

ExperimentsComponent should be create created was false

你似乎有描述和它参数混淆

猜你在找的Angularjs相关文章