Skip to content

Commit 5f075ce

Browse files
38elementseddyerburgh
authored andcommitted
docs: add document for passing text to slots (#257)
* Update options.md * Update options.md
1 parent 1ba86de commit 5f075ce

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

docs/en/api/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ vue-test-utils includes a config object to defined options used by vue-test-util
1212
'transition-group': TransitionGroupStub
1313
}`
1414

15+
The stub stored in `config.stubs` is used by default.
1516
Stubs to use in components. These are overwritten by `stubs` passed in the mounting options.
1617

1718
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 `<!---->`.

docs/en/api/options.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ expect(wrapper.is(Component)).toBe(true)
4141

4242
- type: `{ [name: string]: Array<Component>|Component|string }`
4343

44-
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.
44+
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.
4545

4646
Example:
4747

@@ -54,12 +54,33 @@ const wrapper = shallow(Component, {
5454
slots: {
5555
default: [Foo, Bar],
5656
fooBar: Foo, // Will match `<slot name="FooBar" />`.
57-
foo: '<div />'
57+
foo: '<div />',
58+
bar: 'bar'
5859
}
5960
})
6061
expect(wrapper.find('div')).toBe(true)
6162
```
6263

64+
#### Passing text
65+
66+
You can pass text to `slots`.
67+
There are two limitations to this.
68+
69+
This works with Vue 2.2+.
70+
71+
This works for the text below.
72+
73+
```js
74+
const wrapper = mount(ComponentWithSlots, { slots: { default: 'foobar' }})
75+
```
76+
77+
This does not work for the text below.
78+
79+
```js
80+
const wrapper1 = mount(ComponentWithSlots, { slots: { default: 'foo<span>bar</span>' }})
81+
const wrapper2 = mount(FooComponent, { slots: { default: 'foo {{ bar }}' }})
82+
```
83+
6384
### `stubs`
6485

6586
- type: `{ [name: string]: Component | boolean } | Array<string>`

0 commit comments

Comments
 (0)