>

CODEMASTERYLAB

IDE PLATFORM
CoursesCommunity BlogsKnowledge GraphQuizzesInterview Prep

Sign in to track progress & earn XP

Sign In Create Account
>
Code Mastery Lab

Code Mastery Lab

Sign In

Testing Components — DOM Interaction and Routing

Question 1 / 1

0:00
Core
Medium

A component test sets component.errorMessage = 'Not found' and then asserts that a .error-banner element appears in the DOM. The assertion fails even though the template has <div *ngIf="errorMessage" class="error-banner">. What is missing?

typescript it('shows error banner when errorMessage is set', () => { fixture.detectChanges(); // initial render

component.errorMessage = 'Not found'; // Missing step here

const banner = fixture.nativeElement.querySelector('.error-banner'); expect(banner).toBeTruthy(); // fails });