Bird
0
0

You have this Cypress cleanup code:

medium📝 Debug Q6 of 15
Cypress - Test Organization and Patterns
You have this Cypress cleanup code:
afterEach(() => {
  cy.request('DELETE', '/api/testdata')
})

but the test data is not deleted as expected. What is the most probable reason?
AThe <code>cy.request</code> command is asynchronous and needs to be returned or chained
BThe <code>afterEach</code> hook runs before the test, not after
CThe DELETE API endpoint does not support Cypress requests
DThe test data is deleted but Cypress does not show it in logs
Step-by-Step Solution
Solution:
  1. Step 1: Understand Cypress command chaining

    Cypress commands like cy.request are asynchronous and must be returned or chained to ensure execution completes.
  2. Step 2: Missing return causes premature test completion

    Without returning cy.request, Cypress may finish the hook before the request completes, so data is not deleted.
  3. Final Answer:

    Return or chain the cy.request command in afterEach -> Option A
  4. Quick Check:

    Always return async commands in hooks [OK]
Quick Trick: Return async commands in hooks to ensure completion [OK]
Common Mistakes:
  • Not returning Cypress commands in hooks
  • Assuming afterEach runs before tests
  • Ignoring API endpoint permissions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes