Bird
0
0

Given this test snippet, what will req.request.method output?

medium📝 component behavior Q13 of 15
Angular - Testing
Given this test snippet, what will req.request.method output?
const req = httpMock.expectOne('/api/data');
console.log(req.request.method);
A'GET' if the tested service made a GET request to '/api/data'
B'POST' regardless of the actual request method
CThrows an error because <code>request</code> is undefined
D'PUT' if the tested service made a PUT request to '/api/data'
Step-by-Step Solution
Solution:
  1. Step 1: Understand expectOne returns a TestRequest

    TestRequest has a request property with HTTP method info.
  2. Step 2: The method reflects the actual HTTP call

    If the tested service called GET on '/api/data', req.request.method is 'GET'.
  3. Final Answer:

    'GET' if the tested service made a GET request to '/api/data' -> Option A
  4. Quick Check:

    req.request.method matches actual HTTP method = A [OK]
Quick Trick: expectOne().request.method shows actual HTTP method used [OK]
Common Mistakes:
  • Assuming method is always POST or PUT
  • Thinking request property is undefined
  • Confusing expectOne with expectNone

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes