Bird
0
0

You want to test a service method that makes two HTTP GET requests sequentially. How should you use HttpTestingController to verify both calls?

hard📝 component behavior Q8 of 15
Angular - Testing
You want to test a service method that makes two HTTP GET requests sequentially. How should you use HttpTestingController to verify both calls?
ACall <code>expectOne</code> twice, once for each URL, and flush responses separately
BCall <code>expectOne</code> once with a combined URL string for both requests
CCall <code>expectOne</code> once and flush an array of responses
DCall <code>verify</code> twice, once after each request
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple HTTP calls in tests

    Each HTTP call must be matched by a separate expectOne call.
  2. Step 2: Flush responses individually

    Flush each request separately to simulate server responses.
  3. Final Answer:

    Call expectOne twice, once for each URL, and flush responses separately -> Option A
  4. Quick Check:

    Multiple requests = multiple expectOne and flush calls [OK]
Quick Trick: Match and flush each HTTP call separately with expectOne [OK]
Common Mistakes:
  • Trying to match multiple requests with one expectOne
  • Flushing combined responses instead of individual
  • Misusing verify instead of expectOne for requests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes