Bird
0
0

Consider this test code:

medium📝 Predict Output Q4 of 15
Angular - Testing
Consider this test code:
TestBed.configureTestingModule({ providers: [LoggingService] });
const service = TestBed.inject(LoggingService);
console.log(service.logMessage());

If logMessage() returns 'Logged', what will be printed?
Aundefined
B'Logged'
Cnull
DAn error is thrown
Step-by-Step Solution
Solution:
  1. Step 1: Setup includes LoggingService provider

    The service is properly provided in the testing module.
  2. Step 2: Inject and call method

    TestBed.inject returns an instance, and calling logMessage() returns 'Logged'.
  3. Final Answer:

    'Logged' -> Option B
  4. Quick Check:

    Properly provided service returns expected method output [OK]
Quick Trick: Provided service returns method output as expected [OK]
Common Mistakes:
  • Assuming undefined if service is provided
  • Expecting null instead of actual return
  • Thinking an error occurs without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes