Bird
0
0

What will happen if you place data cleanup code inside a beforeEach hook instead of afterEach in Cypress?

medium📝 Predict Output Q5 of 15
Cypress - Test Organization and Patterns
What will happen if you place data cleanup code inside a beforeEach hook instead of afterEach in Cypress?
ACleanup runs before each test, possibly deleting needed data
BCleanup runs after each test as expected
CCleanup runs only once before all tests
DCleanup does not run at all
Step-by-Step Solution
Solution:
  1. Step 1: Understand beforeEach timing

    The beforeEach hook runs before every test, so cleanup code there runs before tests start.
  2. Step 2: Consider impact on test data

    If cleanup deletes data before tests, tests may fail if they expect that data to exist.
  3. Final Answer:

    Cleanup runs before each test, possibly deleting needed data -> Option A
  4. Quick Check:

    beforeEach runs before tests = Cleanup runs before each test, possibly deleting needed data [OK]
Quick Trick: beforeEach runs before tests, not after [OK]
Common Mistakes:
  • Assuming beforeEach runs after tests
  • Not realizing cleanup may delete needed data
  • Confusing beforeEach with afterEach

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes