Bird
0
0

Examine the following Cypress test code:

medium📝 Debug Q6 of 15
Cypress - Component Testing
Examine the following Cypress test code:
import { mount } from '@cypress/react';
function TextInput() {
  return <input placeholder='Enter text' />;
}
describe('TextInput test', () => {
  it('checks placeholder', () => {
    mount(TextInput);
    cy.get('input').should('have.attr', 'placeholder', 'Enter text');
  });
});

What is the error in this code?
AThe component should be mounted as <TextInput /> instead of TextInput
BThe import statement for mount is incorrect
CThe selector 'input' in cy.get() is invalid
DThe placeholder attribute cannot be tested with should()
Step-by-Step Solution
Solution:
  1. Step 1: Check mount usage

    mount() expects a JSX element, so mount(TextInput) is incorrect.
  2. Step 2: Correct syntax

    It should be mount(<TextInput />) to render the component.
  3. Final Answer:

    The component should be mounted as <TextInput /> instead of TextInput -> Option A
  4. Quick Check:

    mount() requires JSX element, not function reference [OK]
Quick Trick: Use JSX syntax when mounting components [OK]
Common Mistakes:
  • Passing component function instead of JSX
  • Incorrect import path for mount
  • Misusing cy.get() selectors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes