Vue Examples
Mounting Components
Using cy.mount()
To mount a component with cy.mount()
, import the component and pass it to the
method:
import { Stepper } from './Stepper.vue'
it('mounts', () => {
cy.mount(Stepper)
})
Passing Data to a Component
You can pass props and events to a component by setting props
in the options:
- Vue 3
- Vue 2
cy.mount(Stepper, {
props: {
initial: 100,
},
})
cy.mount(Stepper, {
propsData: {
initial: 100,
},
})
Testing Event Handlers
Pass a Cypress spy to an event prop and validate it was called:
it('clicking + fires a change event with the incremented value', () => {
const onChangeSpy = cy.spy().as('onChangeSpy')
cy.mount(Stepper, { props: { onChange: onChangeSpy } })
cy.get('[data-cy=increment]').click()
cy.get('@onChangeSpy').should('have.been.calledWith', 1)
})