CodeZettaInterview Hub

Angular · Testing · Tech Lead · Architecture

How do you test a service that uses HttpClient?

Short Interview Answer

Use HttpClientTestingModule / provideHttpClientTesting and HttpTestingController to flush responses.

Detailed Explanation

Assert method, URL, and body. Verify no outstanding requests. Don't hit real network in unit tests.

Example

const req = httpMock.expectOne('/api/users');
req.flush([{ id: 1 }]);

Did you know this answer?