简体   繁体   中英

How to test angular component with ag-grid

I have an angular component which is using ag-grid . I created an empty test case which is failing with error can not read property includes of undefined .

Inside my component ts file I am using includes keyword only in once place. which is inside column definition object . below is that code.

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

Following is my unit test setup.

 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(); });

I am using mock service which is returning mock object list to display in grid. Inside ngOnInit method of component service is being called. mock list has all value for every property.

Not sure why params is undefined. Any suggestion?

我不确定如何但从描述中删除 fixture.detectchanges() 修复了我的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM