Bird
0
0

Why might placing asynchronous commands inside afterEach without returning a promise cause flaky tests in Cypress?

hard📝 Conceptual Q10 of 15
Cypress - Writing Tests
Why might placing asynchronous commands inside afterEach without returning a promise cause flaky tests in Cypress?
ABecause Cypress may not wait for async commands to finish before starting next test
BBecause afterEach runs before tests, causing timing issues
CBecause asynchronous commands are not allowed in afterEach
DBecause afterEach only runs once after all tests
Step-by-Step Solution
Solution:
  1. Step 1: Understand async behavior in hooks

    If async commands in afterEach are not properly handled, Cypress may proceed without waiting.
  2. Step 2: Effect on test stability

    This causes tests to start before cleanup finishes, leading to flaky or inconsistent results.
  3. Final Answer:

    Because Cypress may not wait for async commands to finish before starting next test -> Option A
  4. Quick Check:

    Always return or chain async commands in hooks [OK]
Quick Trick: Return promises in hooks to avoid flaky tests [OK]
Common Mistakes:
  • Ignoring async nature of commands in hooks
  • Assuming afterEach runs before tests
  • Thinking async commands are disallowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes