单元测试ViewChild,其中包含mat排序和设置内容,Jasmine和Karma

时间:2019-01-10 10:15:04

标签: angular typescript unit-testing angular6 karma-jasmine

我有ViewChildset content。 我想知道如何使用单元测试来测试这段代码。

此图片是代码覆盖率

enter image description here

  @ViewChild(MatSort) set content(content: ElementRef) {
    this.sort = content;
    Iif (this.sort) {
      this.historyReport.sort = this.sort;
    }
  }

1 个答案:

答案 0 :(得分:1)

在依赖项中添加MatSortModule,将为您提供帮助

      imports: [MatSortModule],
      declarations: [],
      providers: [
      ]
    }).compileComponents();```