Arguments:
{Component} component
{Object} options
Returns: {Wrapper}
Options:
See options
Creates a Wrapper
that contains the mounted and rendered Vue component.
Without options:
With Vue options:
Attach to DOM:
Default and named slots:
Stubbing global properties:
Stubbing components:
Deprecation Notice:
When stubbing components, supplying a string (ComponentToStub: '<div class="stubbed" />
) is no longer supported.
Arguments:
{Component} component
{Object} options
{HTMLElement|string} string
{boolean} attachToDocument
{Object} context
{Array<Component|Object>|Component} children
{Object} slots
{Array<Component|Object>|Component|String} default
{Array<Component|Object>|Component|String} named
{Object} mocks
{Object|Array<string>} stubs
{Vue} localVue
Returns: {Wrapper}
Options:
See options
Like mount
, it creates a Wrapper
that contains the mounted and rendered Vue component, but with stubbed child components.
Without options:
With Vue options:
Attach to DOM:
Default and named slots:
Stubbing global properties:
# render()Arguments:
{Component} component
{Object} options
{Object} context
{Array<Component|Object>|Component} children
{Object} slots
{Array<Component|Object>|Component|String} default
{Array<Component|Object>|Component|String} named
{Object} mocks
{Object|Array<string>} stubs
{Vue} localVue
Returns: {Promise<CheerioWrapper>}
Options:
See options
Renders an object to a string and returns a cheerio wrapper .
Cheerio is a jQuery-like library to traverse the DOM in Node.js. It has a similar API to the Vue Test Utils Wrapper
.
render
uses vue-server-renderer
under the hood, to render a component to static HTML.
render
is included in the @vue/server-test-utils
package.
Without options:
With Vue options:
Default and named slots:
Stubbing global properties:
# renderToString()Arguments:
{Component} component
{Object} options
{Object} context
{Array<Component|Object>|Component} children
{Object} slots
{Array<Component|Object>|Component|String} default
{Array<Component|Object>|Component|String} named
{Object} mocks
{Object|Array<string>} stubs
{Vue} localVue
Returns: {Promise<string>}
Options:
See options
Renders a component to HTML.
renderToString
uses vue-server-renderer
under the hood, to render a component to HTML.
renderToString
is included in the @vue/server-test-utils
package.
Without options:
With Vue options:
Default and named slots:
Stubbing global properties:
# SelectorsA lot of methods take a selector as an argument. A selector can either be a CSS selector, a Vue component, or a find option object.
# CSS SelectorsMount handles any valid CSS selector:
div
, foo
, bar
).foo
, .bar
)[foo]
, [foo="bar"]
)#foo
, #bar
)div:first-of-type
)You can also use combinators:
div > #bar > .foo
)div #bar .foo
)div + .foo
)div ~ .foo
)Vue components are also valid selectors.
# Find Option Object # NameUsing a find option object, Vue Test Utils allows for selecting elements by a name
of component on wrapper components.
Using a find option object, Vue Test Utils allows for selecting elements by $ref
on wrapper components.
Arguments:
{Object} options
{Function} errorHandler
Returns:
{Component}
Usage:
createLocalVue
returns a Vue class for you to add components, mixins and install plugins without polluting the global Vue class.
The errorHandler
option can be used to handle uncaught errors during component render function and watchers.
Use it with options.localVue
:
Without options:
With the errorHandler
option:
Arguments:
{vm|HTMLElement} node
{Object} options
{Boolean} attachedToDocument
Returns:
{Wrapper}
Usage:
createWrapper
creates a Wrapper
for a mounted Vue instance, or an HTML element.
Vue Test Utils includes a config object to defined options used by Vue Test Utils.
# Vue Test Utils Config Options #showDeprecationWarnings
Boolean
true
Control whether or not to show deprecation warnings. When set to true
, all deprecation warnings are visible in the console.
Example:
#deprecationWarningHandler
Function
Allows fine-grained control on deprecation warnings. When showDeprecationWarnings
is set to true
, all deprecation warnings will be passed to this handler with method name as first argument and original message as second.
TIP
This could be useful to log deprecation messages to separate location or to help in gradual upgrade of codebase to latest version of test utils by ignoring certain deprecated functions warnings
Example:
#stubs
{ [name: string]: Component | boolean | string }
{}
The stub stored in config.stubs
is used by default. Stubs to use in components. These are overwritten by stubs
passed in the mounting options.
When passing stubs
as an array in the mounting options, config.stubs
are converted to an array, and will stub components with a basic component that returns <${component name}-stub>
.
Example:
#mocks
Object
{}
Like stubs
, the values passed to config.mocks
are used by default. Any values passed to the mounting options mocks
object will take priority over the ones declared in config.mocks
.
Example:
#methods
{ [name: string]: Function }
{}
You can configure default methods using the config
object. This can be useful for plugins that inject methods to components, like VeeValidate . You can override methods set in config
by passing methods
in the mounting options.
Example:
#provide
Object
{}
Like stubs
or mocks
, the values passed to config.provide
are used by default. Any values passed to the mounting options provide
object will take priority over the ones declared in config.provide
. Please take note that it is not supported to pass a function as config.provide
.
Example:
# enableAutoDestroy(hook)Arguments:
{Function} hook
Usage:
enableAutoDestroy
will destroy all created Wrapper
instances using the passed hook function (for example afterEach
). After calling the method, you can revert to the default behavior by calling the resetAutoDestroyState
method.
After calling enableAutoDestroy
you might need to disable auto-destroy behavior (for example when some of your test suites rely on wrapper being persistent across separate tests)
To achieve this you might call resetAutoDestroyState
to disable previously registered hook
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