Bird
0
0

Identify the error in this Cypress code snippet:

medium📝 Debug Q6 of 15
Cypress - Navigation and URL
Identify the error in this Cypress code snippet:

cy.location('pathname').should('equal', '/dashboard')
AThe string '/dashboard' should not have a leading slash
BThe argument 'pathname' should be 'path'
Ccy.location() cannot take arguments
DThe assertion method should be 'eq' not 'equal'
Step-by-Step Solution
Solution:
  1. Step 1: Check assertion method correctness

    Cypress uses 'eq' as the assertion method, not 'equal'.
  2. Step 2: Verify other parts

    'pathname' is correct, cy.location() accepts arguments, and leading slash is valid.
  3. Final Answer:

    The assertion method should be 'eq' not 'equal' -> Option D
  4. Quick Check:

    Use .should('eq', value) for equality [OK]
Quick Trick: Use .should('eq', value) for equality assertions [OK]
Common Mistakes:
  • Using 'equal' instead of 'eq'
  • Wrong property name 'path' instead of 'pathname'
  • Thinking cy.location() takes no arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes