When to use waitForAsync in angular
In Angular 10.1.0, waitForAsync()
has replaced async()
to avoid confusion, but is otherwise exactly the same. Any documentation you see that discusses using async()
will also apply to waitForAsync()
. async()
has been marked as deprecated and will be removed entirely in version 12.
Wraps a test function in an asynchronous test zone. The test will automatically complete when all asynchronous calls within this zone are done. Can be used to wrap an inject call.
So you dont have to manually call done()
callback passed as an argument to mark test had finished or use fakeAsync()
and other helper functions from '@angular/core/testing'
it('...', waitForAsync(inject([AClass], (object) => {
object.doSomething.then(() => {
expect(...);
})
});
See docs.