Bird
0
0

Given this Angular test setup, what will component.getData() return if DataService is replaced by a mock returning 'mock data'?

medium📝 Predict Output Q4 of 15
Angular - Services and Dependency Injection
Given this Angular test setup, what will component.getData() return if DataService is replaced by a mock returning 'mock data'?
A'mock data'
B'real data'
Cundefined
DAn error is thrown
Step-by-Step Solution
Solution:
  1. Step 1: Understand mock service injection

    The mock service replaces the real one, so calls return mock values.
  2. Step 2: Predict method output

    Since mock returns 'mock data', component.getData() returns that string.
  3. Final Answer:

    'mock data' -> Option A
  4. Quick Check:

    Mock service output = B [OK]
Quick Trick: Mock services return their test data when injected [OK]
Common Mistakes:
MISTAKES
  • Expecting real data despite mock injection
  • Assuming undefined if mock is used
  • Thinking an error occurs automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes