NG.VII · Angular 22 practice question
When using `HttpTestingController` within an Angular testing environment set up with `provideHttpClientTesting`, which method should be used to simulate a successful HTTP GET request and allow the test to proceed, compared to a method used to abort a request?
Check answer and explanation
Correct answer: `httpTestingController.expectOne(req).flush({...})`
Explanation
The `httpTestingController.expectOne(req).flush({...})` method is the standard way to intercept a specific request (`req`) and immediately resolve it with predefined test data and status, simulating a successful response. `waitForRequest` is not the primary method for simulation, and `complete` is not the correct simulation API.
Common trap
Students might confuse `flush` (which sends the response) with the methods used to wait or assert on the request.
Source: Testing HTTP with HttpClient - Angular Documentation (https://angular.dev/guide/http/testing)
Checked against the cited text on 2026-11-27.