Mount a simple Vue component and verify its rendered text
Preconditions (2)
✅ Expected Result: The test should pass confirming that the HelloWorld component is mounted and displays the correct text
import { mount } from '@cypress/vue' import HelloWorld from '../../src/components/HelloWorld.vue' describe('HelloWorld Component', () => { it('renders the correct greeting text', () => { mount(HelloWorld) cy.get('div').contains('Hello, Cypress!').should('be.visible') }) })
The test imports the mount function from @cypress/vue and the HelloWorld Vue component.
Inside the test, mount(HelloWorld) mounts the component in a virtual browser environment.
Then, cy.get('div').contains('Hello, Cypress!').should('be.visible') asserts that the component renders the expected text and is visible.
This approach uses Cypress's automatic waiting and clean syntax to keep the test simple and reliable.
Now add data-driven testing to mount the HelloWorld component with different greeting props and verify each greeting text
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