Bird
0
0

How do you configure TestBed to provide a mock service with dependencies instead of the real service?

hard📝 component behavior Q8 of 15
Angular - Testing
How do you configure TestBed to provide a mock service with dependencies instead of the real service?
AOverride the service in <code>schemas</code>
BAdd the mock service to <code>declarations</code>
CImport the mock service in <code>imports</code>
DUse <code>providers</code> with <code>useClass</code> to provide the mock service
Step-by-Step Solution
Solution:
  1. Step 1: Provide mock service in providers

    Use providers array to specify service overrides.
  2. Step 2: Use useClass to replace real service

    Set useClass to the mock implementation.
  3. Final Answer:

    Use providers with useClass to provide the mock service -> Option D
  4. Quick Check:

    Mock services go in providers with useClass [OK]
Quick Trick: Use providers with useClass for mocks [OK]
Common Mistakes:
  • Adding services to declarations
  • Trying to import services as modules
  • Misusing schemas for service overrides

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes