From d86684d9ff7b03b2da52be8aa0ec64203543d605 Mon Sep 17 00:00:00 2001 From: hiendv Date: Tue, 17 Dec 2019 15:33:48 +0700 Subject: [PATCH 1/3] docs: add an example for slots components with props --- docs/api/options.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/api/options.md b/docs/api/options.md index b593f0bc3..15bb8cc62 100644 --- a/docs/api/options.md +++ b/docs/api/options.md @@ -74,6 +74,37 @@ const wrapper = shallowMount(Component, { expect(wrapper.find('div')).toBe(true) ``` +You can also provide slots components with props. +Example: + +```js +const wrapper = mount(Component, { + slots: { + default: `` + }, + mocks: { + val: 'qux' + }, + stubs: { + child: { + props: { + foo: { + type: String, + required: true + } + }, + render(h) { + return h('p', this.foo) + } + } + } +}) + +expect(wrapper.findAll('p').length).toBe(2) +expect(wrapper.text()).toMatch(/bar/) +expect(wrapper.text()).toMatch(/qux/) +``` + ## scopedSlots - type: `{ [name: string]: string|Function }` From cb12659d4372d5291a9a75c450c86347262787c2 Mon Sep 17 00:00:00 2001 From: hiendv Date: Wed, 18 Dec 2019 10:36:03 +0700 Subject: [PATCH 2/3] docs: simplify options API for slots --- docs/api/options.md | 54 ++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/docs/api/options.md b/docs/api/options.md index 15bb8cc62..c2dfbfc44 100644 --- a/docs/api/options.md +++ b/docs/api/options.md @@ -54,12 +54,25 @@ Example: ```js import Foo from './Foo.vue' +import MyComponent from './MyComponent.vue' const bazComponent = { name: 'baz-component', template: '

baz

' } +const yourComponent = { + props: { + foo: { + type: String, + required: true + } + }, + render (h) { + return h('p', this.foo) + } +} + const wrapper = shallowMount(Component, { slots: { default: [Foo, '', 'text'], @@ -67,42 +80,19 @@ const wrapper = shallowMount(Component, { foo: '
', bar: 'bar', baz: bazComponent, - qux: '' - } -}) - -expect(wrapper.find('div')).toBe(true) -``` - -You can also provide slots components with props. -Example: - -```js -const wrapper = mount(Component, { - slots: { - default: `` + qux: '', + quux: '' }, - mocks: { - val: 'qux' + stubs: { // used to register custom components + 'my-component': MyComponent, + 'your-component': yourComponent }, - stubs: { - child: { - props: { - foo: { - type: String, - required: true - } - }, - render(h) { - return h('p', this.foo) - } - } + mocks: { // used to add properties to the rendering context + yourProperty: 'ipsum' } }) -expect(wrapper.findAll('p').length).toBe(2) -expect(wrapper.text()).toMatch(/bar/) -expect(wrapper.text()).toMatch(/qux/) +expect(wrapper.find('div')).toBe(true) ``` ## scopedSlots @@ -348,4 +338,4 @@ const options = { } const wrapper = mount(Component, options) expect(wrapper.text()).toBe('aBC') -``` +``` \ No newline at end of file From be3ee288d63ed60655ded7fee3248367b99989dd Mon Sep 17 00:00:00 2001 From: hiendv Date: Wed, 18 Dec 2019 10:37:34 +0700 Subject: [PATCH 3/3] chore: prettier docs/api --- docs/api/options.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/api/options.md b/docs/api/options.md index c2dfbfc44..ecf1cda5f 100644 --- a/docs/api/options.md +++ b/docs/api/options.md @@ -68,7 +68,7 @@ const yourComponent = { required: true } }, - render (h) { + render(h) { return h('p', this.foo) } } @@ -83,11 +83,13 @@ const wrapper = shallowMount(Component, { qux: '', quux: '' }, - stubs: { // used to register custom components + stubs: { + // used to register custom components 'my-component': MyComponent, 'your-component': yourComponent }, - mocks: { // used to add properties to the rendering context + mocks: { + // used to add properties to the rendering context yourProperty: 'ipsum' } }) @@ -338,4 +340,4 @@ const options = { } const wrapper = mount(Component, options) expect(wrapper.text()).toBe('aBC') -``` \ No newline at end of file +```