Test Overview
This test mounts a simple Vue component using Cypress and verifies that the component renders the expected text content.
This test mounts a simple Vue component using Cypress and verifies that the component renders the expected text content.
import { mount } from 'cypress/vue' import { defineComponent } from 'vue' describe('Mounting Vue components', () => { it('renders the greeting message', () => { const HelloWorld = defineComponent({ template: `<div><h1>Hello, Cypress!</h1></div>` }) mount(HelloWorld) cy.get('h1').should('contain.text', 'Hello, Cypress!') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner initialized | — | PASS |
| 2 | Mount Vue component using mount(HelloWorld) | Browser renders <div><h1>Hello, Cypress!</h1></div> | — | PASS |
| 3 | Find element h1 with cy.get('h1') | h1 element with text 'Hello, Cypress!' is present in DOM | — | PASS |
| 4 | Assert h1 contains text 'Hello, Cypress!' with .should('contain.text', 'Hello, Cypress!') | Text content matches expected string | h1 text contains 'Hello, Cypress!' | PASS |
MyButton in Cypress?cy.mount().cy.mount(MyButton) matches the correct Cypress syntax.cy.mount(MyButton, { props: { label: 'Click me' } })
cy.get('button').should('contain.text', 'Click me')label set to 'Click me'.button element contains the text 'Click me'.cy.mount(MyButton, { props: { label: Click me } })
cy.get('button').should('contain.text', 'Click me')Click me is missing quotes, so it's treated as an undefined variable.AlertBox that accepts a slot for custom message content. Which is the correct way to mount it with a slot containing <p>Warning!</p> in Cypress?slots option with keys for slot names.Warning!
' } }) correctly usesslots: { default: 'Warning!
' } syntax.Pass the test and this pattern moves unknown