Bird
0
0

Identify the error in this test code:

medium📝 Debug Q6 of 15
Cypress - Component Testing
Identify the error in this test code:
cy.mount(MyComponent, { props: { count: 5 } })
cy.get('button').click()
cy.get('count-display').should('contain.text', '6')
AThe selector 'count-display' is missing a dot or hash for class or id.
BThe prop 'count' should be passed as a string, not a number.
CThe click event is not supported on buttons in Cypress.
DThe mount command is missing parentheses.
Step-by-Step Solution
Solution:
  1. Step 1: Check selector syntax

    The selector count-display is used without a dot (.) or hash (#), so Cypress looks for a tag named count-display, which likely does not exist.
  2. Step 2: Validate other parts

    Passing number as prop is valid, clicking buttons is supported, and mount syntax is correct.
  3. Final Answer:

    The selector 'count-display' is missing a dot or hash for class or id. -> Option A
  4. Quick Check:

    CSS selectors need '.' or '#' for classes/ids [OK]
Quick Trick: Use '.' for class and '#' for id in selectors [OK]
Common Mistakes:
  • Using tag name instead of class or id selector
  • Thinking prop types must be strings
  • Assuming click is unsupported in Cypress

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes