Bird
0
0

Given this contract test snippet in JavaScript using Pact:

medium📝 Predict Output Q13 of 15
Rest API - API Testing and Monitoring
Given this contract test snippet in JavaScript using Pact:
provider.addInteraction({
  state: 'user exists',
  uponReceiving: 'a request for user data',
  withRequest: { method: 'GET', path: '/user/123' },
  willRespondWith: { status: 200, body: { id: 123, name: 'Alice' } }
});

What will happen if the provider returns status 404 instead of 200 during the test?
AThe test will pass because the body matches the contract
BThe test will fail because the status code doesn't match the contract
CThe test will ignore the status code and only check the path
DThe test will pass if the response time is fast enough
Step-by-Step Solution
Solution:
  1. Step 1: Understand the contract test expectation

    The contract expects a 200 status code with a specific body when requesting '/user/123'.
  2. Step 2: Analyze the provider's actual response

    The provider returns 404, which does not match the expected 200 status code.
  3. Final Answer:

    The test will fail because the status code doesn't match the contract -> Option B
  4. Quick Check:

    Status mismatch causes test failure [OK]
Quick Trick: Mismatch in status code causes contract test failure [OK]
Common Mistakes:
MISTAKES
  • Assuming body match overrides status code mismatch
  • Ignoring status code in contract tests
  • Thinking response time affects contract test result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes