Test Overview
This test sets up a simple React component in Cypress for testing. It verifies that the component renders correctly with the expected text.
This test sets up a simple React component in Cypress for testing. It verifies that the component renders correctly with the expected text.
import React from 'react'; import { mount } from 'cypress/react18'; function Greeting({ name }) { return <h1>Hello, {name}!</h1>; } describe('Greeting component', () => { it('renders greeting message', () => { mount(<Greeting name="Alice" />); cy.get('h1').should('contain.text', 'Hello, Alice!'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner is ready | - | PASS |
| 2 | Mount the Greeting component with prop name='Alice' | React component Greeting is rendered inside Cypress iframe | - | PASS |
| 3 | Find the <h1> element | The DOM contains <h1>Hello, Alice!</h1> | cy.get('h1') locates the heading element | PASS |
| 4 | Check that <h1> contains text 'Hello, Alice!' | The heading text is visible | cy.get('h1').should('contain.text', 'Hello, Alice!') verifies correct text | PASS |