Bird
0
0

What is wrong with this Angular test provider setup?

medium📝 Debug Q14 of 15
Angular - Testing
What is wrong with this Angular test provider setup?
providers: [{ provide: RealService, useValue: MockService }]
AMissing import for RealService
BuseValue expects an instance, not a class reference
CuseValue cannot be used in providers
Dprovide should be MockService, not RealService
Step-by-Step Solution
Solution:
  1. Step 1: Understand useValue usage

    useValue expects an actual instance or object, not a class reference.
  2. Step 2: Identify the mistake

    MockService is a class, but useValue is given the class itself, not an instance like new MockService().
  3. Final Answer:

    useValue expects an instance, not a class reference -> Option B
  4. Quick Check:

    useValue needs instance, not class [OK]
Quick Trick: useValue needs instance (new), not class name [OK]
Common Mistakes:
  • Passing class instead of instance to useValue
  • Confusing provide token with mock class
  • Assuming useValue can't be used in providers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes