Test Overview
This test triggers a custom event on a button and verifies that the event handler updates the page content as expected.
This test triggers a custom event on a button and verifies that the event handler updates the page content as expected.
describe('Custom event trigger test', () => { it('should trigger a custom event and update text', () => { cy.visit('https://example.cypress.io/commands/actions') cy.get('#action-canvas') .trigger('myCustomEvent', { detail: { message: 'Hello Cypress!' } }) cy.get('#custom-event-output').should('contain.text', 'Hello Cypress!') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner is ready | — | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io/commands/actions' | Page with various action examples is loaded | Page loaded successfully | PASS |
| 3 | Find element with id 'action-canvas' | Element '#action-canvas' is visible on the page | Element exists and is visible | PASS |
| 4 | Trigger custom event 'myCustomEvent' on '#action-canvas' with detail { message: 'Hello Cypress!' } | Custom event dispatched on the element | Event handler updates '#custom-event-output' text | PASS |
| 5 | Find element with id 'custom-event-output' and check text contains 'Hello Cypress!' | Element '#custom-event-output' shows updated text | Text contains 'Hello Cypress!' | PASS |
cy.trigger() do in Cypress when testing web pages?cy.trigger()cy.trigger() is used in Cypress to simulate events like clicks or custom events on elements.myEvent on an element with id #btn in Cypress?cy.get(), then call .trigger() with the event name.cy.get('#input').trigger('customChange', { detail: { value: 42 } })trigger method can send custom events with additional data via the detail property.cy.get('#form').trigger('submit', { bubbles: true }).submit() command.dataReady on a div with id #container. This event should carry a payload with a list of items. Which code correctly triggers this event with the payload { items: [1, 2, 3] } and ensures event bubbles up?detail object when triggering events.detail with the payload and sets bubbles: true. Other options either miss detail or have wrong payload keys or bubbling.Pass the test and this pattern moves unknown