Bird
0
0

Given this Cypress test snippet using API-first setup:

medium📝 Predict Output Q13 of 15
Cypress - Test Organization and Patterns
Given this Cypress test snippet using API-first setup:
cy.request('POST', '/api/users', {name: 'Alice'}).then((response) => {
  expect(response.status).to.eq(201)
  cy.visit('/users/' + response.body.id)
})

What will happen if the API returns status 400 instead of 201?
AThe test will continue and visit the user page anyway.
BThe test will throw a syntax error.
CThe test will fail at the assertion checking response.status.
DThe test will ignore the response and pass.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the assertion on response status

    The test expects response.status to equal 201.
  2. Step 2: Understand behavior if status is 400

    If status is 400, the assertion expect(response.status).to.eq(201) fails and test stops with failure.
  3. Final Answer:

    The test will fail at the assertion checking response.status. -> Option C
  4. Quick Check:

    Assertion fails if response.status != 201 [OK]
Quick Trick: Assertion fails if API response status is unexpected [OK]
Common Mistakes:
  • Assuming test continues after failed assertion
  • Thinking Cypress throws syntax error on bad status
  • Believing test ignores failed API responses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes