ag-grid angular2 中的单元测试- fixture.nativeElement.query 不是函数

ag-grid unit testing in angular2- fixture.nativeElement.query is not a function

我在angular中使用Karma/Jasmine为ag-grid写了一个测试用例。在我的测试用例中,只是检查 ag-grid headers 并出现 "fixture.nativeElement.query is not a function" 之类的错误,但我不确定这是否是我编写的正确方法。如果有人有想法请帮助我。

这是我的测试用例

it('to test the column headers',()=>{
    fixture.nativeElement.query(By.css(".ag-fresh"))
    .map(function (header){
      return header.getText()
    }).then(function(headers){
      expect(headers).toEqual(['color','qty','price']);
    });
  });

您应该在 fixture.debugElement 上使用 query()。而且我认为您不需要 map 此处的结果。

fixture.debugElement.query(By.css(".ag-fresh")).nativeElement 应该为你做。