Bird
0
0

You want to test that a cookie named theme is set to dark only after clicking a button. Which Cypress code correctly waits for the button click and then verifies the cookie?

hard📝 Application Q8 of 15
Cypress - Authentication and Sessions
You want to test that a cookie named theme is set to dark only after clicking a button. Which Cypress code correctly waits for the button click and then verifies the cookie?
Acy.get('button#themeToggle').click() cy.getCookie('theme').should('have.value', 'dark')
Bcy.getCookie('theme').should('have.property', 'value', 'dark') cy.get('button#themeToggle').click()
Ccy.get('button#themeToggle').click() cy.getCookie('theme').should('have.property', 'value', 'dark')
Dcy.get('button#themeToggle').click() cy.getCookie('theme').should('not.exist')
Step-by-Step Solution
Solution:
  1. Step 1: Ensure button click happens before checking cookie

    The cookie is set after clicking the button, so click must come first.
  2. Step 2: Use correct assertion syntax

    The assertion should check the cookie's 'value' property equals 'dark'. cy.get('button#themeToggle').click() cy.getCookie('theme').should('have.property', 'value', 'dark') does this correctly.
  3. Final Answer:

    Click button then assert cookie value is 'dark' -> Option C
  4. Quick Check:

    Click then check cookie value = Correct order [OK]
Quick Trick: Always perform actions before asserting their effects [OK]
Common Mistakes:
  • Checking cookie before clicking button
  • Using wrong assertion like 'have.value'
  • Asserting cookie does not exist after click

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes