【问题标题】:AG-Grid gridReady not being called on tests with Angular and JestAG-Grid gridReady 未在使用 Angular 和 Jest 的测试中调用
【发布时间】:2021-12-09 04:37:10
【问题描述】:

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

这里有我的测试代码:

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 你可以看到它的代码沙箱。 Here 是一个 GitHub 存储库。

【问题讨论】:

    标签: angular jestjs ag-grid ag-grid-angular angular-testing-library


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-05-06
      • 1970-01-01
      • 2020-02-28
      • 2021-04-03
      • 2017-07-07
      • 2017-04-29
      • 2021-11-26
      • 2020-11-23
      • 1970-01-01
      相关资源
      最近更新 更多