Bird
0
0

Identify the issue in this Angular test setup:

medium📝 Debug Q6 of 15
Angular - Testing
Identify the issue in this Angular test setup:
TestBed.configureTestingModule({});
const service = TestBed.inject(NotificationService);
ATesting module should import BrowserModule
BTestBed.inject() is deprecated and should not be used
CNotificationService is not provided in the testing module
DService instance must be created with new keyword
Step-by-Step Solution
Solution:
  1. Step 1: Check providers in configureTestingModule

    The providers array is empty, so NotificationService is not registered.
  2. Step 2: Consequence of missing provider

    Injecting a service not provided causes an error at runtime.
  3. Final Answer:

    NotificationService is not provided in the testing module -> Option C
  4. Quick Check:

    Always provide services before injecting [OK]
Quick Trick: Always provide services in TestBed before injecting [OK]
Common Mistakes:
  • Assuming TestBed.inject() is deprecated
  • Thinking BrowserModule import is required for services
  • Creating service instance manually instead of DI

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes