Mid From PDF Angular Angular

How do you test asynchronous code in Angular tests?

  • Use async/await with Angular's waitForAsync or Jasmine’s done callback.
  • Use Angular’s fakeAsync and tick() to simulate asynchronous passage of time.

Example with fakeAsync:

it('should fetch data asynchronously', fakeAsync(() => {

let data;

service.getData().subscribe(result => data = result);

tick(); // simulate async time passing

expect(data).toEqual(['expected data']);

}));

More from Angular Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details