Bird
0
0

How can you configure TestBed to override a component's template for testing purposes?

hard📝 Application Q9 of 15
Angular - Testing
How can you configure TestBed to override a component's template for testing purposes?
AUse <code>TestBed.overrideTemplate(Component, 'new template')</code> before creating the component
BChange the template property inside <code>configureTestingModule</code>
CModify the component's template file directly
DSet the template in the component instance after creation
Step-by-Step Solution
Solution:
  1. Step 1: Recall TestBed override methods

    TestBed.overrideTemplate allows replacing a component's template during testing.
  2. Step 2: Exclude invalid approaches

    Changing template in configureTestingModule or modifying files directly is not supported; setting template after creation has no effect.
  3. Final Answer:

    Use TestBed.overrideTemplate(Component, 'new template') before creating the component -> Option A
  4. Quick Check:

    Override template with TestBed.overrideTemplate [OK]
Quick Trick: Override templates before component creation [OK]
Common Mistakes:
  • Trying to set template in configureTestingModule
  • Editing source files for tests
  • Changing template after component instance creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes