A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://vue-test-utils.vuejs.org/api/options below:

Website Navigation


Mounting Options | Vue Test Utils

# Mounting Options

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

# context

Passes context to functional component. Can only be used with functional components .

Example:

# data

Passes data to a component. It will merge with the existing data function.

Example:

# slots

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

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

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:

# mocks

Add additional properties to the instance. Useful for mocking global injections.

Example:

TIP

To mock $root please use parentComponent option instead as described here

# localVue

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:

# attachTo

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

# attachToDocument

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.

# attrs

Set the component instance's $attrs object.

# propsData

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.

# listeners

Set the component instance's $listeners object.

Example:

# parentComponent

Component to use as parent for mounted component.

Example:

# provide

Pass properties for components to use in injection. See provide/inject .

Example:

# Other options

When 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