如何使用 ag-grid 测试 angular 组件

How to test angular component with ag-grid

我有一个 angular 组件正在使用 ag-grid。我创建了一个空的测试用例,它因错误 can not read property includes of undefined.

而失败

在我的组件 ts 文件中,我只在一个地方使用 includes 关键字。在列定义 object 内。下面是代码。

cellClass: function (params) {
    return params.value.includes('Fail') ? 'status-fail' : null;
  }

以下是我的单元测试设置。

 beforeEach(async(() => {  
    TestBed.configureTestingModule({
      declarations: [BannerComponent,CheckComponent,LinkComponent],
      imports: [
        RouterTestingModule, 
        FormsModule,
        HttpClientModule,  
        BsDatepickerModule.forRoot(),
        DatepickerModule.forRoot(),
        AgGridModule.withComponents([CheckComponent,LinkComponent])],
      providers: [
          { provide: BannerService, useClass: MockBannerService },         
        { provide: ActivatedRoute, useValue: {paramMap:of(convertToParamMap({Id: 1}))} }
    ],
      schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
    })
    .compileComponents();
    fixture = TestBed.createComponent(BannerComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
}));
  fit('should create', () => {
    fixture.detectChanges();
    expect(component).toBeTruthy();
  });

我正在使用模拟服务,它返回模拟对象列表以显示在网格中。正在调用组件服务的 ngOnInit 内部方法。模拟列表具有每个 属性.

的所有值

不确定为什么 params 未定义。 有什么建议吗?

我不确定如何从 describe 中删除 fixture.detectchanges() 解决了我的问题。