1

The gridReady method of the Angular AG Grid is not being called in the Jest tests. Do you know why?

Here you have my test code:

import {TestBed} from "@angular/core/testing";
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from "@angular/platform-browser-dynamic/testing";
import {AppComponent} from "./app.component";
import {FormsModule} from "@angular/forms";
import {AgGridModule} from "ag-grid-angular";

describe('AG Grid', () => {
  it('calls grid ready', async()=> {
    TestBed.resetTestEnvironment();
    TestBed.initTestEnvironment(BrowserDynamicTestingModule,
      platformBrowserDynamicTesting());

    await TestBed.configureTestingModule({
      imports: [
        FormsModule,
        AgGridModule.withComponents([]),
      ],
      declarations: [AppComponent]
    }).compileComponents();

    const fixture = TestBed.createComponent(AppComponent);
    const component = fixture.componentInstance;

    fixture.detectChanges();
    expect(component.api).toBeDefined();
    expect(component.columnApi).toBeDefined();

  });
})

Here you can see a code sandbox for it. Here is a GitHub repository.

Jöcker
  • 5,281
  • 2
  • 38
  • 44

1 Answers1

1

The problem is solved using await fixture.whenStable() after fixture.detectChanges()

Jöcker
  • 5,281
  • 2
  • 38
  • 44