Test Overview
This test checks if a React component receives the correct props and if clicking a button triggers the expected event handler.
This test checks if a React component receives the correct props and if clicking a button triggers the expected event handler.
describe('Props and event testing', () => { it('should render with correct props and handle click event', () => { const onClickSpy = cy.spy().as('clickHandler'); cy.mount(<MyButton label="Click me" onClick={onClickSpy} />); cy.get('button').should('have.text', 'Click me'); cy.get('button').click(); cy.get('@clickHandler').should('have.been.calledOnce'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner is ready to execute the test | - | PASS |
| 2 | Mount the MyButton component with label prop 'Click me' and onClick event handler spy | Component is rendered in the test DOM with a button showing text 'Click me' | - | PASS |
| 3 | Find the button element | Button element with text 'Click me' is found in the DOM | Check button text equals 'Click me' | PASS |
| 4 | Click the button | Button is clicked by the test | - | PASS |
| 5 | Verify the onClick event handler spy was called once | Spy function recorded one call from the button click | Spy was called exactly once | PASS |