Bird
0
0

Find the mistake in this test snippet:

medium📝 Debug Q7 of 15
Cypress - Component Testing
Find the mistake in this test snippet:
cy.mount(MyComponent, { props: { visible: true } })
cy.get('.modal').should('be.visible')
cy.get('.close-btn').click()
cy.get('.modal').should('not.exist')
AThe selector '.close-btn' is invalid without an id.
BThe mount command is missing the component import statement.
CThe prop 'visible' should be passed as a string 'true'.
DThe last assertion should use 'not.be.visible' instead of 'not.exist'.
Step-by-Step Solution
Solution:
  1. Step 1: Understand modal visibility vs existence

    Clicking the close button likely hides the modal but does not remove it from the DOM, so checking not.exist will fail.
  2. Step 2: Correct assertion usage

    The correct assertion is not.be.visible to check the modal is hidden but still present.
  3. Final Answer:

    The last assertion should use 'not.be.visible' instead of 'not.exist'. -> Option D
  4. Quick Check:

    Hidden elements exist but are not visible [OK]
Quick Trick: Use 'not.be.visible' to check hidden elements, not 'not.exist' [OK]
Common Mistakes:
  • Confusing visibility with existence
  • Thinking props must be strings
  • Assuming selectors need ids

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes