From 2ee0739d20e8e2eb9123a2d87497ed3b299f69a1 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Fri, 30 Nov 2018 19:40:55 +0000 Subject: [PATCH 1/3] fix: stub component options object --- packages/create-instance/patch-render.js | 19 ++++++++++++++++++- test/specs/mounting-options/slots.spec.js | 2 +- test/specs/shallow-mount.spec.js | 11 +++++------ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/create-instance/patch-render.js b/packages/create-instance/patch-render.js index fb3b463d3..6190990e2 100644 --- a/packages/create-instance/patch-render.js +++ b/packages/create-instance/patch-render.js @@ -50,6 +50,10 @@ function isConstructor (el) { return typeof el === 'function' } +function isComponentOptions (el) { + return typeof el === 'object' && (el.template || el.render) +} + export function patchRender (_Vue, stubs, stubAllComponents) { // This mixin patches vm.$createElement so that we can stub all components // before they are rendered in shallow mode. We also need to ensure that @@ -60,7 +64,10 @@ export function patchRender (_Vue, stubs, stubAllComponents) { function patchRenderMixin () { const vm = this - if (vm.$options.$_doNotStubChildren || vm._isFunctionalContainer) { + if ( + vm.$options.$_doNotStubChildren || + vm.$options._isFunctionalContainer + ) { return } @@ -84,6 +91,16 @@ export function patchRender (_Vue, stubs, stubAllComponents) { return originalCreateElement(Constructor, ...args) } + if (isComponentOptions(el)) { + console.log(el) + if (stubAllComponents) { + const stub = createStubFromComponent(el, el.name || 'anonymous') + return originalCreateElement(stub, ...args) + } + + return originalCreateElement(el, ...args) + } + if (typeof el === 'string') { let original = resolveComponent(el, originalComponents) diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js index 5d70a404d..e06b1381c 100644 --- a/test/specs/mounting-options/slots.spec.js +++ b/test/specs/mounting-options/slots.spec.js @@ -56,7 +56,7 @@ describeWithMountingMethods('options.slots', mountingMethod => { } }) - it('mounts component with default slot if passed object with template prop in slot object', () => { + it('mounts component with default slot if passed compiled options in slot object', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: [compiled] } diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index d4c65cf47..f4596d616 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -445,10 +445,10 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const TestComponent = { template: `
- - - - + + + +
`, components: { ChildComponent }, @@ -472,7 +472,6 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.text()).to.equal('') - expect(wrapper.findAll(ChildComponent).length).to.equal(4) + expect(wrapper.html()).to.equal('
') }) }) From 18ffe159cb1e779385783ad0a04700297f6cd6af Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Fri, 30 Nov 2018 21:16:19 +0000 Subject: [PATCH 2/3] refactor: move function --- packages/create-instance/patch-render.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/packages/create-instance/patch-render.js b/packages/create-instance/patch-render.js index 6190990e2..e0a773a72 100644 --- a/packages/create-instance/patch-render.js +++ b/packages/create-instance/patch-render.js @@ -80,27 +80,16 @@ export function patchRender (_Vue, stubs, stubAllComponents) { return originalCreateElement(el, ...args) } - if (isConstructor(el)) { + if (isConstructor(el) || isComponentOptions(el)) { if (stubAllComponents) { const stub = createStubFromComponent(el, el.name || 'anonymous') return originalCreateElement(stub, ...args) } - const Constructor = shouldExtend(el, _Vue) ? extend(el, _Vue) : el return originalCreateElement(Constructor, ...args) } - if (isComponentOptions(el)) { - console.log(el) - if (stubAllComponents) { - const stub = createStubFromComponent(el, el.name || 'anonymous') - return originalCreateElement(stub, ...args) - } - - return originalCreateElement(el, ...args) - } - if (typeof el === 'string') { let original = resolveComponent(el, originalComponents) From 46ed468564e2f0253cfe7d7da928eae7d13aaa0a Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Fri, 30 Nov 2018 21:25:10 +0000 Subject: [PATCH 3/3] refactor: break assertion into multiple lines --- test/specs/shallow-mount.spec.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index f4596d616..e04ee2dd5 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -472,6 +472,13 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.equal('
') + expect(wrapper.html()).to.equal( + '
' + + ' ' + + ' ' + + ' ' + + '' + + '
' + ) }) })