Bird
0
0

You wrote this Cypress test:

medium📝 Debug Q14 of 15
Cypress - Writing Tests
You wrote this Cypress test:
describe('Sample', () => {
  beforeEach(() => {
    cy.visit('/dashboard')
  })

  afterEach(() => {
    cy.clearCookies
  })

  it('checks title', () => {
    cy.title().should('include', 'Dashboard')
  })
})

Why does cy.clearCookies not run after the test?
ABecause <code>cy.clearCookies</code> is missing parentheses to call the function
BBecause <code>afterEach</code> only runs before tests
CBecause <code>cy.clearCookies</code> is not a valid Cypress command
DBecause <code>beforeEach</code> overrides <code>afterEach</code>
Step-by-Step Solution
Solution:
  1. Step 1: Check the afterEach hook code

    The code uses cy.clearCookies without parentheses, so the function is not called.
  2. Step 2: Understand function call syntax

    To execute the command, parentheses are required: cy.clearCookies().
  3. Final Answer:

    Because cy.clearCookies is missing parentheses to call the function -> Option A
  4. Quick Check:

    Functions need () to run [OK]
Quick Trick: Always add () to call Cypress commands [OK]
Common Mistakes:
  • Forgetting parentheses on Cypress commands
  • Confusing beforeEach and afterEach roles
  • Assuming afterEach runs before tests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes