Performance: Testing HTTP calls with HttpTestingController
MEDIUM IMPACT
This concept affects the speed and reliability of frontend tests that simulate HTTP calls without real network delays.
it('should fetch data with HttpTestingController', () => { service.getData().subscribe(data => { expect(data).toBeTruthy(); }); const req = httpTestingController.expectOne('/api/data'); req.flush({ key: 'value' }); httpTestingController.verify(); });
it('should fetch data', (done) => {
service.getData().subscribe(data => {
expect(data).toBeTruthy();
done();
});
});| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Real HTTP calls in tests | N/A | N/A | N/A | [X] Bad |
| HttpTestingController mocks | N/A | N/A | N/A | [OK] Good |