Skip to content

Commit f321669

Browse files
feat: add global.stubs
1 parent 79ed2b7 commit f321669

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/api/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,62 @@ test('mocks a vuex store', async () => {
353353
})
354354
```
355355

356+
### `global.stubs`
357+
358+
Stubs a component for all Vue Instances.
359+
360+
`Component.vue`:
361+
362+
```vue
363+
<template>
364+
<div><foo/></div>
365+
</template>
366+
367+
<script>
368+
import Foo from '@/Foo.vue'
369+
export default {
370+
components: { Foo }
371+
}
372+
</script>
373+
```
374+
375+
`Component.spec.js`:
376+
377+
```js
378+
test('stubs a component using simple Array', () => {
379+
const wrapper = mount(Component, {
380+
global: {
381+
stubs: ['Foo']
382+
}
383+
})
384+
385+
expect(wrapper.html()).toEqual('<div><foo-stub></div>')
386+
})
387+
388+
test('stubs a component using an Object boolean syntax', () => {
389+
const wrapper = mount(Component, {
390+
global: {
391+
stubs: { Foo: true }
392+
}
393+
})
394+
395+
expect(wrapper.html()).toEqual('<div><foo-stub></div>')
396+
})
397+
398+
test('stubs a component using a custom component', () => {
399+
const FooMock = {
400+
name: 'Foo',
401+
template: 'FakeFoo'
402+
}
403+
const wrapper = mount(Component, {
404+
global: {
405+
stubs: { Foo: FooMock }
406+
}
407+
})
408+
409+
expect(wrapper.html()).toEqual('<div>FakeFoo</div>')
410+
})
411+
```
356412

357413
## Wrapper
358414

0 commit comments

Comments
 (0)