I am working with AG-Grid and I have to write unit test case for the createDef method. I have something like this.
createColDef(){
const colDef = {
//all the coldef's goes here
}
this.gridApi.refreshCells();
return colDef;
}
Now when I write unit test case for the createColDef method I get error saying "TypeError: Cannot read properties of undefined (reading 'refreshCells')" . Also, I have all these codes in grid.service.ts
Below is sample of how my spec.ts file looks
it('should return the correct columndef', () => {
const result = service.createColumnDef();
const expectedColDef = [//expected coldef];
expect(JSON.stringify(result)).toEqual(JSON.stringify(expectedColDef));
});
How do I overcome this gridApi issue. Please help!