Angular · Middle · Question 48 of 75
How do you test a service that uses HttpClient without real network calls?
- ✓Correct answer: Provide
provideHttpClient()andprovideHttpClientTesting(), then useHttpTestingControllerto expect and flush requests - 2Start a real server for each test
- 3Replace
window.fetchwith a function returningundefined
Explanation
httpTesting.expectOne('/api/users').flush([...]) returns a fake response, and verify() in afterEach ensures no unexpected requests were made.