Skip to content

Commit cb12659

Browse files
committed
docs: simplify options API for slots
1 parent d86684d commit cb12659

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

docs/api/options.md

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,55 +54,45 @@ Example:
5454

5555
```js
5656
import Foo from './Foo.vue'
57+
import MyComponent from './MyComponent.vue'
5758

5859
const bazComponent = {
5960
name: 'baz-component',
6061
template: '<p>baz</p>'
6162
}
6263

64+
const yourComponent = {
65+
props: {
66+
foo: {
67+
type: String,
68+
required: true
69+
}
70+
},
71+
render (h) {
72+
return h('p', this.foo)
73+
}
74+
}
75+
6376
const wrapper = shallowMount(Component, {
6477
slots: {
6578
default: [Foo, '<my-component />', 'text'],
6679
fooBar: Foo, // Will match `<slot name="FooBar" />`.
6780
foo: '<div />',
6881
bar: 'bar',
6982
baz: bazComponent,
70-
qux: '<my-component />'
71-
}
72-
})
73-
74-
expect(wrapper.find('div')).toBe(true)
75-
```
76-
77-
You can also provide slots components with props.
78-
Example:
79-
80-
```js
81-
const wrapper = mount(Component, {
82-
slots: {
83-
default: `<child foo="bar"/><child :foo="val"/>`
83+
qux: '<my-component />',
84+
quux: '<your-component foo="lorem"/><your-component :foo="yourProperty"/>'
8485
},
85-
mocks: {
86-
val: 'qux'
86+
stubs: { // used to register custom components
87+
'my-component': MyComponent,
88+
'your-component': yourComponent
8789
},
88-
stubs: {
89-
child: {
90-
props: {
91-
foo: {
92-
type: String,
93-
required: true
94-
}
95-
},
96-
render(h) {
97-
return h('p', this.foo)
98-
}
99-
}
90+
mocks: { // used to add properties to the rendering context
91+
yourProperty: 'ipsum'
10092
}
10193
})
10294

103-
expect(wrapper.findAll('p').length).toBe(2)
104-
expect(wrapper.text()).toMatch(/bar/)
105-
expect(wrapper.text()).toMatch(/qux/)
95+
expect(wrapper.find('div')).toBe(true)
10696
```
10797

10898
## scopedSlots
@@ -348,4 +338,4 @@ const options = {
348338
}
349339
const wrapper = mount(Component, options)
350340
expect(wrapper.text()).toBe('aBC')
351-
```
341+
```

0 commit comments

Comments
 (0)