Angular6-Jasmin因果单元测试无法读取未定义的属性

时间:2019-04-25 06:33:41

标签: unit-testing angular6 karma-jasmine

我的ngOnInit()代码如下

  ngOnInit(){
  this.isProjectEdit = this._sharedData.isProjectEdit;
  如果(this.isProjectEdit){
    this.projectModel.projectName = this._sharedData.projectDet;
    this.projectModel.projectDescription = this._sharedData.projectDesc;
  }否则,如果(!this.isProjectEdit){
    this.projectModel.projectName =“”;
    this.projectModel.projectDescription =“”;
  }
}
 

我已经为上述代码创建了单元测试代码。

  it(“应该屏蔽ngOninit”,()=> {
    fixture.componentInstance.isProjectEdit = false;
    Fixture.componentInstance.projectModel = {
      projectName:“测试”,
      projectId:0,
      projectVisualization:错误,
      projectDescription:“测试”
    };
    Fixture.detectChanges();
    Expect(fixture.componentInstance.isProjectEdit).toBe(false);
  });
 

在运行测试时出现错误“无法读取未定义的属性'isProjectEdit'”。

0 个答案:

没有答案