'Jasmine AG Grid Test case failed

Am trying to write a test for ag grid export method. Here is the component changes

export class GridComponent extendsimplements OnInit {

  gridApi: any;

  onGridDataExport(): void {
    this.gridApi.exportDataAsCsv();
  }
}

grid component spec file

fdescribe('when onGridDataExport method call', () => {
    it('should call gridApi', () => {
      const result = spyOn(component.gridApi, 'exportDataAsCsv');
      component.onGridDataExport();
      expect(result).toHaveBeenCalled();
    });

  });

when i run the test cases it show the below error enter image description here

How can i resolve this issue?

expecting a valid solution.

Thanks in advance



Solution 1:[1]

Try with this:

fdescribe('when onGridDataExport method call', () => {
    it('should call gridApi', () => {
      const result = spyOn(component.gridApi, 'exportDataAsCsv').and.callThrough();
      component.onGridDataExport();
      expect(result).toHaveBeenCalled();
    });
});

If you look my code, I'm adding .and.callThrough(); and you need to use this because with this code you're really waiting for the execution of the method exportDataAsCsv.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ricky