From 429ad87b43729bc3a135eb7161507a470babfb30 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Thu, 19 Jul 2018 13:06:21 +0200 Subject: [PATCH 1/2] Render props on auto stubs --- packages/shared/stub-components.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/shared/stub-components.js b/packages/shared/stub-components.js index c56412de6..08eba852e 100644 --- a/packages/shared/stub-components.js +++ b/packages/shared/stub-components.js @@ -104,9 +104,18 @@ function createBlankStub ( return { ...getCoreProperties(componentOptions), - render (h) { + render (h, context) { return h( tagName, + { + attrs: componentOptions.functional ? { + ...context.data.attrs, + ...context.props + } : { + ...this.$attrs, + ...this.$props + } + }, !componentOptions.functional && this.$slots.default ) } From 072eb469d25ae4615fb779199131ef72144e028d Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 28 Jul 2018 09:38:05 +0100 Subject: [PATCH 2/2] test: add test --- packages/shared/stub-components.js | 5 ++--- test/specs/shallow-mount.spec.js | 35 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/shared/stub-components.js b/packages/shared/stub-components.js index 08eba852e..2d08e055b 100644 --- a/packages/shared/stub-components.js +++ b/packages/shared/stub-components.js @@ -109,10 +109,9 @@ function createBlankStub ( tagName, { attrs: componentOptions.functional ? { - ...context.data.attrs, - ...context.props + ...context.props, + ...context.data.attrs } : { - ...this.$attrs, ...this.$props } }, diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index 970230cef..aeae2a559 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -100,6 +100,41 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } ) + itDoNotRunIf( + vueVersion < 2.2, // $props does not exist in Vue < 2.2 + 'renders stubs props', () => { + const TestComponent = { + template: ``, + data: () => ({ + 'propA': 'a' + }), + components: { + child: { + props: ['prop'] + } + } + } + const wrapper = shallowMount(TestComponent) + expect(wrapper.html()).to.contain(' { + const TestComponent = { + template: ``, + data: () => ({ + 'propA': 'a' + }), + components: { + Child: { + props: ['prop'], + functional: true + } + } + } + const wrapper = shallowMount(TestComponent) + expect(wrapper.html()).to.contain(' { const TestComponent = { template: `