Bird
0
0

Identify the error in this Cypress code snippet:

medium📝 Debug Q6 of 15
Cypress - Authentication and Sessions
Identify the error in this Cypress code snippet:
cy.setCookie('id', 12345)
cy.getCookie('id').should('have.property', 'value', 12345)
ACookie value must be a string, not a number
BMissing semicolon after setCookie
CgetCookie does not support should assertions
DCookie name cannot be 'id'
Step-by-Step Solution
Solution:
  1. Step 1: Check the cookie value type

    Cypress requires cookie values to be strings, but 12345 is a number here.
  2. Step 2: Understand assertion failure cause

    The assertion compares the cookie value property to a number, which will fail because the actual value is stored as a string.
  3. Final Answer:

    Cookie value must be a string, not a number -> Option A
  4. Quick Check:

    Cookie values are strings always [OK]
Quick Trick: Always pass cookie values as strings in setCookie [OK]
Common Mistakes:
  • Passing numbers instead of strings as cookie values
  • Assuming semicolons are mandatory in Cypress commands
  • Thinking getCookie cannot be asserted

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes