Skip to content

Commit a891178

Browse files
committed
2 parents 7733d19 + 77defdd commit a891178

File tree

1 file changed

+59
-12
lines changed

1 file changed

+59
-12
lines changed

src/api/README.md

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ test('slots - default and named', () => {
9191
})
9292
```
9393

94-
## `global`
94+
## Global
9595

96-
Global is an object of options that is applied to the component and all it's children.
96+
You can provide properties to the App instance using the properties under the `global` mount property.
9797

98-
### `provide`
98+
### `global.provide`
9999

100100
Provides data to be received in a `setup` function via `inject`.
101101

@@ -139,14 +139,14 @@ const ThemeSymbol = Symbol()
139139

140140
mount(Component, {
141141
global: {
142-
provides: {
142+
provide: {
143143
[ThemeSymbol]: 'value'
144144
}
145145
}
146146
})
147147
```
148148

149-
### `mixins`
149+
### `global.mixins`
150150

151151
Applies mixins via `app.mixin(...)`.
152152

@@ -178,7 +178,7 @@ test('adds a lifecycle mixin', () => {
178178
})
179179
```
180180

181-
### `plugins`
181+
### `global.plugins`
182182

183183
Installs plugins on the component.
184184

@@ -213,6 +213,53 @@ test('installs a plugin via `plugins`', () => {
213213
})
214214
```
215215

216+
217+
### `global.components`
218+
219+
Registers components globally to all components
220+
221+
```js
222+
test('installs a component globally', () => {
223+
import GlobalComponent from '@/components/GlobalComponent'
224+
225+
const Component = {
226+
template: '<div><global-component/></div>'
227+
}
228+
const wrapper = mount(Component, {
229+
global: {
230+
components: {
231+
GlobalComponent
232+
}
233+
}
234+
})
235+
236+
expect(wrapper.find('.global-component').exists()).toBe(true)
237+
})
238+
```
239+
240+
### `global.directives`
241+
242+
Registers a directive globally to all components
243+
244+
```js
245+
test('installs a directive globally', () => {
246+
import Directive from '@/directives/Directive'
247+
248+
const Component = {
249+
template: '<div v-bar>Foo</div>'
250+
}
251+
const wrapper = mount(Component, {
252+
global: {
253+
directives: {
254+
Bar: Directive
255+
}
256+
}
257+
})
258+
259+
expect(wrapper.classes()).toContain('added-by-bar')
260+
})
261+
```
262+
216263
## Wrapper
217264

218265
When you use `mount`, a `VueWrapper` is returned with a number of useful methods for testing. A `VueWrapper` is a thin wrapper around your component instance. Methods like `find` return a `DOMWrapper`, which is a thin wrapper around the DOM nodes in your component and it's children. Both implement a similar same API.
@@ -288,7 +335,7 @@ Similar to `find`, but instead returns an array of `DOMWrapper`.
288335
```vue
289336
<template>
290337
<div>
291-
<span
338+
<span
292339
v-for="number in [1, 2, 3]"
293340
:key="number"
294341
data-test="number"
@@ -431,8 +478,8 @@ export default {
431478
test('emitted', () => {
432479
const wrapper = mount(Component)
433480

434-
console.log(wrapper.emitted())
435-
// {
481+
console.log(wrapper.emitted())
482+
// {
436483
// greet: [ ['hello'], ['goodbye'] ]
437484
// }
438485

@@ -444,10 +491,10 @@ test('emitted', () => {
444491
### `setValue`
445492

446493
Sets a value on DOM element, including:
447-
- `<input>` (either `type="checkbox" or `type="radio"`)
494+
- `<input>` (either `type="checkbox"` or `type="radio"`)
448495
- `<select>`
449496

450-
Since this will often result in a DOM re-render, `setValue` returns `Vue.nextTick`, so you will often have to call this with `await` to ensure the DOM has been updated before making an assertion.
497+
Since this will often result in a DOM re-render, `setValue` returns `Vue.nextTick`, so you will often have to call this with `await` to ensure the DOM has been updated before making an assertion.
451498

452499
```vue
453500
<template>
@@ -475,4 +522,4 @@ test('checked', async () => {
475522
await wrapper.find('input').setChecked(false)
476523
expect(wrapper.find('div')).toBeFalsy()
477524
})
478-
```
525+
```

0 commit comments

Comments
 (0)