Options for mount
and shallow
. The options object can contain both vue-test-utils
mounting options and raw Vue options.
Vue options are passed to the component when a new instance is created. , e.g. store
, propsData
. For a full list, see the Vue API docs.
- type:
Object
Passes context to functional component. Can only be used with functional components.
Example:
const wrapper = mount(Component, {
context: {
props: { show: true }
}
})
expect(wrapper.is(Component)).toBe(true)
- type:
{ [name: string]: Array<Component>|Component|string }
Provide an object of slot contents to the component. The key corresponds to the slot name. The value can be either a component, an array of components, or a template string.
Example:
import { expect } from 'chai'
import Foo from './Foo.vue'
import Bar from './Bar.vue'
const wrapper = shallow(Component, {
slots: {
default: [Foo, Bar],
fooBar: Foo, // Will match <slot name="FooBar" />,
foo: '<div />'
}
})
expect(wrapper.find('div')).toBe(true)
- type:
{ [name: string]: Component | boolean } | Array<string>
Stubs child components. Can be an Array of component names to stub, or an object.
Example:
import Foo from './Foo.vue'
mount(Component, {
stubs: ['registered-component']
})
shallow(Component, {
stubs: {
// stub with a specific implementation
'registered-component': Foo,
// create default stub
'another-component': true
}
})
- type:
Object
Add additional properties to the instance. Useful for mocking global injections.
Example:
import { expect } from 'chai'
const $route = { path: 'http://www.example-path.com' }
const wrapper = shallow(Component, {
mocks: {
$route
}
})
expect(wrapper.vm.$route.path).toBe($route.path)
- type:
Vue
A local copy of Vue created by createLocalVue to use when mounting the component. Installing plugins on this copy of Vue prevents polluting the original Vue
copy.
Example:
import { createLocalVue, mount } from 'vue-test-utils'
import VueRouter from 'vue-router'
import { expect } from 'chai'
import Foo from './Foo.vue'
const localVue = createLocalVue()
localVue.use(VueRouter)
const routes = [
{ path: '/foo', component: Foo }
]
const router = new VueRouter({
routes
})
const wrapper = mount(Component, {
localVue,
router
})
expect(wrapper.vm.$route).toBeInstanceOf(Object)
- type:
boolean
- default:
false
Component will be attach to DOM when rendered if set to true
. This can be used with hasStyle
to check multi element CSS selectors.
- type:
Object
Set the component instance's $attrs
object.
- type:
Object
Set the component instance's $listeners
object.
- type:
boolean
- default:
true
Clones component before mounting if true
, which avoids mutating the original component definition.
options.mocks
(Object
): Add globals to Vue instance.
options.localVue
(Object
): vue class to use in mount
. See createLocalVue