Resolving the "n timer(s) still in the queue" Error In Angular Unit Tests
A few months ago one of the developers I work with ran into the below error in an Angular unit test:
1 timer(s) still in the queue
The fix was to specify a particular amount of time in the tick() call as shown below:
Hoping this helps someone!
1 timer(s) still in the queue
The fix was to specify a particular amount of time in the tick() call as shown below:
it('should set accountConfirmationDetails when getAccountConfirmationDetails is called', fakeAsync(() => {
// Arrange
let spyGetAccountConfirmationDetails = spyOn(accountService, 'getAccountConfirmationDetails')
.and
.returnValue(Promise.resolve(AccountMockData.mockAccountConfirmationDetails));
// Act
fixture.detectChanges();
tick(15000);
// Assert
expect(spyGetPaymentConfirmationDetails).toHaveBeenCalled();
expect(comp.zone).toBe(42);
expect(comp.hasValidProfile).toBeTruthy();
}));
Hoping this helps someone!
Comments
I still don't understand what fixture.detectChanges() is doing that causes the timer to be stuck in the queue. I also don't know how to see tasks that are in the queue. Do you?
Did you ever find out why this is the case? I suspect it's because of some asynchronous operation that's started but *not recognized* by tick() but *is* recognized by the angular zone when it realizes there are still timers in the queue...
thanks
I was about to Talon E from balcony.
:D
Now i can move on to test some more.
So you delayed the Talon E.
Thank you
Post a Comment