NG.X · Angular 22 practice question

When testing a Lightswitch component that exposes a clicked() method and a message property, which question requires component DOM testing rather than a class-only unit test?

Choose one answer
Check answer and explanation

Correct answer: Whether clicked() is bound in the template so a user can trigger it and see message displayed.

Explanation

Verifying that clicked() is bound to a template element for the user to invoke and that message is actually rendered requires testing the component together with its DOM.

Common trap

This is tempting because toggling state is part of the component's behavior, but checking an internal field after calling a method directly can be done in a class-only test. This is tempting because strict compilation catches many template errors, but compilation alone does not verify runtime DOM behavior or user interaction.

Source: Angular docs: Basics of testing components — Component DOM testing
Checked against the cited text on 2026-11-25.

Report an error in this question