NG.X · Angular 22 practice question
After registering provideHttpClientTesting() in TestBed, which token should a test inject to expect and answer outgoing HTTP requests?
const httpTesting = TestBed.inject(HttpTestingController);
Check answer and explanation
Correct answer: HttpTestingController
Explanation
Injecting HttpTestingController via TestBed.inject(HttpTestingController) gives the test access to the controller used to match and respond to pending HTTP requests.
Common trap
This is tempting because older NgModule-based Angular tests imported HttpClientTestingModule, but it is a module rather than the injectable controller. This is tempting because HttpHandlerFn is used in functional interceptors, but it is not the testing controller token.
Source: Angular docs: Test requests — Expecting and answering requests
Checked against the cited text on 2026-11-25.