NG.X · Angular 22 practice question
A developer writes unit tests that instantiate a component class directly with new MyComponent() and check its methods. Why are these class-only tests insufficient on their own?
Check answer and explanation
Correct answer: They cannot verify DOM rendering, user input handling, or integration with parent and child components.
Explanation
Testing only the TypeScript class misses everything that happens in the template and DOM, including whether the component renders properly, handles user input and gestures, or integrates with parent and child components.
Common trap
This is tempting because TestBed is the standard way to test components, but instantiating a component class directly in plain TypeScript is possible; it just leaves the template and DOM untested. This is tempting because signals are tied to Angular's reactivity model, but reading and updating signals works in plain class tests without a DOM.
Source: Angular docs: Basics of testing components — Component DOM testing
Checked against the cited text on 2026-11-25.