Options for mount
and shallowMount
.
TIP
Aside from the options documented below, the options
object can contain any option that would be valid in a call to new Vue ({ /*options here*/ })
. These options will be merged with the component's existing options when mounted with mount
/ shallowMount
See other options for examples
# contextObject
Passes context to functional component. Can only be used with functional components .
Example:
# dataFunction
Passes data to a component. It will merge with the existing data
function.
Example:
# slots{ [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, or text.
Example:
# scopedSlots{ [name: string]: string|Function }
Provide an object of scoped slots to the component. The key corresponds to the slot name.
You can set the name of the props using the slot-scope attribute:
Otherwise props are available as a props
object when the slot is evaluated:
You can also pass a function that takes the props as an argument:
Or you can use JSX. If you write JSX in a method, this.$createElement
is auto-injected by babel-plugin-transform-vue-jsx:
Root Element required
Due to the internal implementation of this feature, the slot content has to return a root element, even though a scoped slot is allowed to return an array of elements.
If you ever need this in a test, the recommended workaround is to wrap the component under test in another component and mount that one:
# stubs{ [name: string]: Component | string | boolean } | Array<string>
Stubs child components can be an Array of component names to stub, or an object. If stubs
is an Array, every stub is <${component name}-stub>
.
Deprecation Notice:
When stubbing components, supplying a string (ComponentToStub: '<div class="stubbed" />
) is no longer supported.
Example:
# mocksObject
Add additional properties to the instance. Useful for mocking global injections.
Example:
TIP
To mock $root
please use parentComponent
option instead as described here
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:
# attachToHTMLElement | string
null
This either specifies a specific HTMLElement or CSS selector string targeting an HTMLElement, to which your component will be fully mounted in the document.
When attaching to the DOM, you should call wrapper.destroy()
at the end of your test to remove the rendered elements from the document and destroy the component instance.
TIP
When using attachTo: document.body
new div
instead of replacing entire body new <div>
will be appended. This is designed to mimic Vue3 behavior and simplify future migration. See this comment for details
boolean
false
Deprecation warning
attachToDocument
is deprecated and will be removed in future releases. Use attachTo
instead. For example, if you need to attach the component to the document.body:
For more information, see attachTo
's tip above.
Like attachTo
, but automatically creates a new div
element for you and inserts it into the body.
When attaching to the DOM, you should call wrapper.destroy()
at the end of your test to remove the rendered elements from the document and destroy the component instance.
Object
Set the component instance's $attrs
object.
Object
Set the component instance's props when the component is mounted.
Example:
TIP
It's worth noting that propsData
is actually a Vue API , not a Vue Test Utils mounting option. It is processed through extends
. Please see Other options.
Object
Set the component instance's $listeners
object.
Example:
# parentComponentObject
Component to use as parent for mounted component.
Example:
# provideObject
Pass properties for components to use in injection. See provide/inject .
Example:
# Other optionsWhen the options for mount
and shallowMount
contain the options other than the mounting options, the component options are overwritten with those using extends .
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4