Bird
0
0

How should you set an @Input() property value in an Angular component test before verifying the rendered template?

hard📝 Application Q8 of 15
Angular - Testing
How 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 array
CModify the input property in the component's constructor
DAssign the input property on the component instance and call fixture.detectChanges()
Step-by-Step Solution
Solution:
  1. Step 1: Set input property on component instance

    Directly assign the input value on the component instance before change detection.
  2. Step 2: Trigger change detection

    Call fixture.detectChanges() to update the template with the new input value.
  3. Step 3: Verify rendered output

    After detectChanges(), the template reflects the input property value.
  4. Final Answer:

    Assign the input property on the component instance and call fixture.detectChanges() -> Option D
  5. Quick 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 declarations
  • Changing inputs inside constructor instead of test

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes