NG.X · Angular 22 practice question

A team normally runs unit tests in the default Node.js environment for speed. In which situation should they run their tests in a real browser instead?

Choose one answer
Check answer and explanation

Correct answer: When tests rely on browser-specific APIs such as rendering, or when debugging in a browser.

Explanation

Although Node.js is faster for most unit tests, running in a real browser is useful when tests depend on browser-specific APIs like rendering or when you need browser debugging.

Common trap

This is tempting because TestBed is an Angular testing utility, but service injection with TestBed.inject() runs fine in the default Node.js environment. This is tempting because HTTP requests normally happen in a browser, but provideHttpClientTesting() intercepts requests in memory and does not require a real browser.

Source: Angular docs: Unit testing — Running tests in a browser
Checked against the cited text on 2026-11-25.

Report an error in this question