Testing intervalTimer from async and fakeAsync

Willwsharp

The Angular Testing Guide section about testing components with asynchronous services says that:

Writing test functions with done, while more cumbersome than async and fakeAsync, is a viable and occasionally necessary technique. For example, you can't call async or fakeAsync when testing code that involves the intervalTimer, as is common when testing async Observable methods.

Does anyone know what intervalTimer is or why it can't be tested from async or asyncFake?

Willwsharp

The intervalTimer is most likely in reference to setInterval or any other timer functionality and the reason it can't be used with async or fakeAsync is because async (from my understanding) usually uses the whenStable function on the ComponentFixture, and whenStable will never actually be called since the timer promise will never finish. Using fakeAsync will actually throw an error because it tries to perform the test synchronously but when it finishes, it detects that there's still a promise yet to be resolved so it throws an error.

I got this from posting an issue on Angular's GitHub repo. Here is the link to the issue: https://github.com/angular/angular/issues/20711

The part regarding the whenStable is not in that question but from researching it on my own it looks like whenStable and async are generally used together.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What is the difference between fakeAsync and async in angular2 testing

What is the difference between FakeAsync and quiver.testing.async?

What is the difference between angular testing async+whenStable and fakeAsync+tick?

Does Async / FakeAsync wait for .then in spec blocks or just the component/class it's testing?

FakeAsync/tick (Async/whenStable) vs detectChanges()

Testing anonymous async function inside of an RxJS from

testing the async function passed as a prop from parent to child

Unit testing value of Observable returned from service (using async pipe)

Testing subsequent function call on an Async function from React function component

What is the difference between fakeAsync's tick() and done() in angular2 testing?

async task testing

Jasmine Async Testing

spring testing @async method

Testing async function with jasmine

Testing for exceptions in async methods

MSUnit Testing Async Hell

Testing an async injectable service

Testing async SQS sendMessage

Testing async microservices with no API

Why using `fakeAsync` test does not make test code run in async way?

Angular Unit Test including FileReader.onload doesn't work with async/whenStable nor fakeAsync/tick

Can not find module import { async, TestBed } from '@angular/core/testing'; import { IonicModule } from 'ionic-angular';

When unit testing, how do I mock a return null from async method?

Angular[karma] Async testing on Observable

unit testing async task in csharp

Testing an async function with Jasmine in Meteor

Angular Formbuilder testing with Async Validator

Spring integration : testing async flows

Jest testing of async middleware for authentication