The Angular Testing Guide section about testing components with asynchronous services says that:
Writing test functions with
done
, while more cumbersome thanasync
andfakeAsync
, is a viable and occasionally necessary technique. For example, you can't callasync
orfakeAsync
when testing code that involves theintervalTimer
, as is common when testing asyncObservable
methods.
Does anyone know what intervalTimer
is or why it can't be tested from async
or asyncFake
?
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.
Comments