0

gridReady在 Jest 测试中没有调用 Angular AG Grid的方法。你知道为什么吗?

这里有我的测试代码:

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

  });
})

在这里,您可以看到它的代码沙箱。 是一个 GitHub 存储库。

4

1 回答 1

0

使用await fixture.whenStable()后问题解决了fixture.detectChanges()

于 2021-10-25T08:03:53.013 回答