Angular Karma, what is causing "flush failed after reaching the limit of 20 tasks. Does your...

Discussão em 'Angular' iniciado por L8Cod3r, Abril 23, 2025.

  1. L8Cod3r

    L8Cod3r Guest

    I'm testing a component that internally uses several services and sub-components. This test fails with "flush failed after reaching the limit of 20 tasks. Does your code use a polling timeout?" Calling discardPeriodicTasks(); fixes this, however, I'd like to find what timer is still running, because I don't think there should be any.


    it('Create view and get the data', fakeAsync(() => {
    console.debug('[TEST] Start');
    expect(component).toBeTruthy();
    expect(component).toBeInstanceOf(MyComponent);
    fixture.detectChanges();
    expect(component.tradeGrid).toBeDefined();
    tick(1); // sends request
    dataProviderMock.fakeServerResp({ reqId: "1", ver: "" }, jsonResp1 as MsgRespType);
    tick(1); // receives response
    fixture.detectChanges();
    expect(component.gridApi).toBeDefined();
    let gridData: GridRow[] = [];
    component.gridApi.forEachNode((rowNode, index) => {
    gridData.push(rowNode.data);
    });
    expect(gridData.length).toEqual(2);
    expect(gridData[0].tid).toEqual("4ZCF2");
    expect(gridData[1].tid).toEqual("4ZCFE");
    dataProviderMock.close();
    // discardPeriodicTasks(); // <-- uncomment, no error
    flush(); // <-- error
    }));

    Continue reading...

Compartilhe esta Página