Bird
0
0

What will happen if you run this Cypress test?

medium📝 Predict Output Q5 of 15
Cypress - Component Testing
What will happen if you run this Cypress test?
import { mount } from '@cypress/react';
function Label() {
  return <label>Name:</label>;
}
describe('Label test', () => {
  it('checks label text', () => {
    mount(<Label />);
    cy.get('label').should('contain.text', 'Name');
  });
});
AThe test will fail because 'contain.text' is not a valid assertion.
BThe test will pass because the label contains the text 'Name'.
CThe test will fail because the label element is not rendered.
DThe test will pass but the assertion is case-sensitive and will fail.
Step-by-Step Solution
Solution:
  1. Step 1: Check the component output

    The Label component renders a label element with text 'Name:'.
  2. Step 2: Understand the assertion

    The assertion uses should('contain.text', 'Name') which checks if the label text includes 'Name'. This is true.
  3. Final Answer:

    The test will pass because the label contains the text 'Name'. -> Option B
  4. Quick Check:

    contain.text assertion = pass if substring matches [OK]
Quick Trick: Use 'contain.text' to check partial text in element [OK]
Common Mistakes:
  • Thinking 'contain.text' is invalid
  • Assuming exact match required for 'contain.text'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes