spectator.fixture.whenStable() not working in unittest

381 Views Asked by At

In our ionic unit test we are migrate our existing unit test to spectator unit test.

What we are doing here is we initialise our unit test with beforeEach.

beforeEach(async() => {
    spectator = createComponent()
    generalConfigService = TestBed.inject(GeneralConfigService)
    spyOn(spectator.component.generalService, 'getGeneralConfigState').and.returnValue(of(configDataMock))
    spectator.component.chartElement = chartViewInputMock.chartElement
    spectator.component.chartElementID = "0123456789"
    spectator.component.localstorageservice.setStoragedata('WXcurrentLevelInfo', { "level": "plant", "id": "64291", "timezone": { "abbr": "UTC", "offset": 0, "name": "UTC" } })
    spectator.component.localstorageservice.setStoragedata('PlantID', "64291")
    spectator.component.localstorageservice.setStoragedata('appConfigData', loginSuccessMock.appConfigData)
    await spectator.component.ngOnInit();
})

After this we try to run one case.

it('user can able to duplicate element if dashboard limit not excced',(async(done) => {
    let spy = spyOn(spectator.component.commonService,'alertMessage')
    popoverSpy.onDidDismiss.and.returnValue(Promise.resolve({data:'chartDuplicate'}));
    spectator.component.chartPopover('') // once execution of this function done than only I have to called next lines
    await spectator.fixture.whenStable() /// Never resolve so got error of timeout in unittest
    expect(popoverSpy.present).toHaveBeenCalled();
    expect(alertSpy.present).toHaveBeenCalled()
    done()
}))

So actual issue is spectator.fixture.whenStable() is some times worked correctly but generally it not resolved.So what we are writing after that line never executes and provide error like

Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

0

There are 0 best solutions below