Skip to content

Commit d0cff2b

Browse files
committed
docs: add docs on global config
1 parent 463712b commit d0cff2b

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

docs/api/index.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,7 @@ Finds a Vue Component instance and returns a `VueWrapper` if one is found, other
798798
799799
```vue
800800
<template>
801-
<div class="foo">
802-
Foo
803-
</div>
801+
<div class="foo">Foo</div>
804802
</template>
805803

806804
<script>
@@ -924,9 +922,7 @@ Similar to `findComponent`, `getComponent` looks for a Vue Component instance an
924922
925923
```vue
926924
<template>
927-
<div class="foo">
928-
Foo
929-
</div>
925+
<div class="foo">Foo</div>
930926
</template>
931927

932928
<script>
@@ -1274,3 +1270,44 @@ test('unmount', () => {
12741270
### `vm`
12751271
12761272
This is the `Vue` instance. You can access all of the [instance methods and properties of a vm](https://v3.vuejs.org/api/instance-properties.html) with `wrapper.vm`. This only exists on `VueWrapper`.
1273+
1274+
## Global Config
1275+
1276+
### `config.global`
1277+
1278+
Instead of configuring global mounting options on a per-test basis, you can configure them globally. These will be used by default every time you `mount` a component. You can override the defaults by via mounting options.
1279+
1280+
An example might be globally mocking the `$t` variable from vue-i18n, globally stubbing out a component, or registering a global component:
1281+
1282+
```js
1283+
import { config, mount } from '@vue/test-utils'
1284+
import { h } from 'vue'
1285+
1286+
config.global.mocks = {
1287+
$t: message => message
1288+
}
1289+
1290+
config.global.stubs = {
1291+
'my-component': {
1292+
name: 'my-component'
1293+
render() {
1294+
return h('div')
1295+
}
1296+
}
1297+
}
1298+
1299+
const Component = {
1300+
components: {
1301+
MyComponent
1302+
},
1303+
template: `
1304+
<p>{{ $t('message') }}</p>
1305+
<my-component />
1306+
`
1307+
}
1308+
1309+
it('uses global config', () => {
1310+
const wrapper = mount(Component)
1311+
console.log(wrapper.html()) // <p>message</p><my-component-stub />
1312+
})
1313+
```

0 commit comments

Comments
 (0)