NG.X · Angular 22 practice question
Given a ComponentFixture in an Angular component test, which property gives direct access to the component's root DOM element?
const bannerElement: HTMLElement = fixture.nativeElement;
Check answer and explanation
Correct answer: fixture.nativeElement
Explanation
The fixture exposes the component's host DOM element directly through fixture.nativeElement.
Common trap
This is tempting because componentInstance is a real ComponentFixture property, but it returns the TypeScript component class instance rather than the DOM element. This is tempting because ElementRef is used inside components to reference host elements, but ComponentFixture exposes nativeElement and debugElement instead.
Source: Angular docs: Basics of testing components — `DebugElement`
Checked against the cited text on 2026-11-25.