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:

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

Popular Posts

Silent Renew and the "login_required" Error When Using oidc-client

How to Get Norton Security Suite Firewall to Allow Remote Desktop Connections in Windows

Fixing the "Please add a @Pipe/@Directive/@Component annotation" Error In An Angular App After Upgrading to webpack 4

How to Determine if a Column Exists in a DataReader