Bird
0
0

Which of the following is the correct syntax to use afterEach in a Cypress test file?

easy📝 Syntax Q12 of 15
Cypress - Writing Tests
Which of the following is the correct syntax to use afterEach in a Cypress test file?
AafterEach { cy.visit('/home') }
BafterEach(() => { cy.visit('/home') })
CafterEach: () => cy.visit('/home')
DafterEach => { cy.visit('/home') }
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct function syntax in Cypress

    Cypress hooks use function calls with arrow functions inside parentheses, like afterEach(() => { ... }).
  2. Step 2: Identify syntax errors in other options

    Options B, C, and D miss parentheses or use incorrect arrow function syntax.
  3. Final Answer:

    afterEach(() => { cy.visit('/home') }) -> Option B
  4. Quick Check:

    Hook syntax = function call with arrow function [OK]
Quick Trick: Hooks need parentheses and arrow functions: hook(() => {}) [OK]
Common Mistakes:
  • Omitting parentheses after hook name
  • Using curly braces without parentheses
  • Incorrect arrow function syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes