Bird
0
0

What is wrong with this Cypress test code?

medium📝 Debug Q7 of 15
Cypress - Writing Tests
What is wrong with this Cypress test code?
describe('Suite', () => {
  afterEach(() => {
    cy.log('Cleaning up')
  })
  after(() => {
    cy.log('Done')
  })
  before(() => {
    cy.log('Start')
  })
  it('Test 1', () => {
    cy.log('Running')
  })
})
Acy.log cannot be used inside hooks
BNo error; code is correct
Cbefore hook should be before after hooks
DafterEach hook cannot be used with after hook
Step-by-Step Solution
Solution:
  1. Step 1: Review hook usage

    Using before, afterEach, and after hooks together is valid in Cypress.
  2. Step 2: Check cy.log usage

    cy.log works inside hooks and tests without issue.
  3. Final Answer:

    No error; code is correct -> Option B
  4. Quick Check:

    Hooks can be combined; cy.log works anywhere [OK]
Quick Trick: Multiple hooks can coexist; cy.log works in all [OK]
Common Mistakes:
  • Thinking hooks conflict
  • Believing cy.log is invalid in hooks
  • Assuming hook order causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes