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']);
}));