【问题标题】:.length is not taking in Jasmine Karma unit testing.length 不参加 Jasmine Karma 单元测试
【发布时间】:2018-07-07 19:15:22
【问题描述】:

谁能帮我解决以下问题。

错误:TypeError:无法读取未定义的属性“长度”

组件文件:

 @Input()
   allPropertyLines: any[];

 @Input()
   completedPropertyLines: any[];

 allPropertyLength: number = 0;
 completedPropertyLength: number = 0;

  ngOnInit() {
      this.allPropertyLength = this.allPropertyLines.length;
      this.completedPropertyLength = this.completedPropertyLines.length;      
   }

规格文件:

 beforeEach(() => {
   fixture = TestBed.createComponent(ListPropertyComponent);
   comp = fixture.componentInstance;
   comp.ngOnInit();    
 });
it('should create component', () => expect(comp).toBeDefined());

【问题讨论】:

    标签: angular ionic3 karma-jasmine karma-coverage angular-test


    【解决方案1】:

    谢谢大家!!它有效。

    需要记住的一个简单的事情是我应该提供如下所示的输入。

    comp.allPropertyLines = [{}]。

    【讨论】:

      猜你喜欢
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 2018-02-26
      相关资源
      最近更新 更多