Bird
0
0

Identify the issue in this Cypress test code:

medium📝 Debug Q6 of 15
Cypress - Writing Tests
Identify the issue in this Cypress test code:
describe('Example Suite', () => {
  beforeEach(() => {
    cy.visit('/')
  })
  after(() => {
    cy.clearCookies
  })
  it('Sample Test', () => {
    cy.get('button').click()
  })
})
AUsing <code>beforeEach</code> instead of <code>before</code> for visit
BMissing parentheses after <code>cy.clearCookies</code> in the after hook
CThe <code>it</code> block is missing a callback function
DThe <code>cy.get</code> selector is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Review after hook

    The after hook calls cy.clearCookies without parentheses, so the function is not invoked.
  2. Step 2: Confirm other parts

    beforeEach with cy.visit is valid; it has a proper callback; selector is valid.
  3. Final Answer:

    Missing parentheses after cy.clearCookies in the after hook -> Option B
  4. Quick Check:

    Check function invocation syntax [OK]
Quick Trick: Always call Cypress commands with parentheses [OK]
Common Mistakes:
  • Forgetting parentheses on Cypress commands
  • Confusing beforeEach with before
  • Assuming selectors are invalid without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes