Angular - TestingHow should you set an @Input() property value in an Angular component test before verifying the rendered template?AChange the input property after calling fixture.detectChanges()BSet the input property in the TestBed declarations arrayCModify the input property in the component's constructorDAssign the input property on the component instance and call fixture.detectChanges()Check Answer
Step-by-Step SolutionSolution:Step 1: Set input property on component instanceDirectly assign the input value on the component instance before change detection.Step 2: Trigger change detectionCall fixture.detectChanges() to update the template with the new input value.Step 3: Verify rendered outputAfter detectChanges(), the template reflects the input property value.Final Answer:Assign the input property on the component instance and call fixture.detectChanges() -> Option DQuick Check:Set input before detectChanges() to update template. [OK]Quick Trick: Set input on component then call detectChanges() [OK]Common Mistakes:Setting input after detectChanges()Trying to set inputs via TestBed declarationsChanging inputs inside constructor instead of test
Master "Testing" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Advanced Patterns - Smart and dumb component pattern - Quiz 9hard Animations - Why Angular animations matter - Quiz 8hard Internationalization and Accessibility - ARIA attributes in templates - Quiz 2easy Internationalization and Accessibility - Marking text for translation - Quiz 9hard Server-Side Rendering - Hydration behavior - Quiz 9hard Server-Side Rendering - Pre-rendering static pages - Quiz 9hard Standalone Components - Standalone pipes and directives - Quiz 10hard Standalone Components - Migrating from NgModules - Quiz 14medium State Management - When NgRx is overkill - Quiz 12easy State Management - Signals as modern state primitive - Quiz 8hard