Bird
0
0

What is wrong with this test snippet?

medium📝 Debug Q7 of 15
Angular - Testing
What is wrong with this test snippet?
const req = httpMock.expectOne('/api/items');
req.flush({ data: 'test' });
httpMock.expectOne('/api/items');
ASecond expectOne will throw because no new request was made
Bflush must be called after all expectOne calls
CexpectOne cannot be called twice with the same URL
Dflush cannot send an object as response
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the test flow

    First expectOne matches a request and flushes a response.
  2. Step 2: Check second expectOne call

    No new request was made after flush, so second expectOne throws error.
  3. Final Answer:

    Second expectOne will throw because no new request was made -> Option A
  4. Quick Check:

    expectOne requires a matching new request each time [OK]
Quick Trick: Each expectOne must match a new HTTP request [OK]
Common Mistakes:
  • Calling expectOne multiple times without new requests
  • Misunderstanding flush timing
  • Thinking flush response must be primitive type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes