Bird
0
0

What will happen when this Cypress code runs?

medium📝 Predict Output Q5 of 15
Cypress - Authentication and Sessions
What will happen when this Cypress code runs?
cy.clearLocalStorage('session').then(cleared => {
  cy.log(cleared)
})
AThrows an error because 'session' is not a valid argument
BClears all local storage and logs true
CClears only the 'session' key from local storage and logs true
DDoes nothing and logs false
Step-by-Step Solution
Solution:
  1. Step 1: Understand cy.clearLocalStorage with key

    Passing a key clears only that key from local storage.
  2. Step 2: Check return value

    It returns true if key existed and was cleared, so cy.log prints true.
  3. Final Answer:

    Clears only the 'session' key from local storage and logs true -> Option C
  4. Quick Check:

    cy.clearLocalStorage(key) clears key and returns true [OK]
Quick Trick: Pass key to clearLocalStorage to remove specific item [OK]
Common Mistakes:
  • Thinking it clears all storage with a key argument
  • Expecting error on valid key argument
  • Assuming it returns false always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes