Bird
0
0

What will be the output of the following Cypress test snippet?

medium📝 Predict Output Q5 of 15
Cypress - Authentication and Sessions
What will be the output of the following Cypress test snippet?
cy.request('POST', '/api/login', { user: 'test', pass: '1234' })
  .then(({ body }) => {
    expect(body).to.have.property('token');
  });
ATest fails if response body has 'token' property
BSyntax error due to destructuring
CTest passes if response body has 'token' property
DRuntime error due to missing 'token'
Step-by-Step Solution
Solution:
  1. Step 1: Understand destructuring in .then()

    The response object is destructured to get body, which is valid syntax.
  2. Step 2: Check assertion logic

    The test expects body to have a token property. If present, the assertion passes.
  3. Final Answer:

    Test passes if response body has 'token' property -> Option C
  4. Quick Check:

    Assertion on token property = Pass if present [OK]
Quick Trick: Destructure response to access body easily [OK]
Common Mistakes:
  • Thinking destructuring causes syntax error
  • Assuming test fails if token exists
  • Confusing property check with value check

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes