From 4338403fe59dcf0b3e5d3fb099227ba87623834b Mon Sep 17 00:00:00 2001 From: Edd Yerburgh Date: Sat, 1 Dec 2018 09:54:00 +0000 Subject: [PATCH] fix: stub dynamic components (#1051) --- packages/create-instance/patch-render.js | 12 +++++++++--- test/specs/mounting-options/slots.spec.js | 2 +- test/specs/shallow-mount.spec.js | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/create-instance/patch-render.js b/packages/create-instance/patch-render.js index b06c72c80..b4911ebbc 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 } @@ -73,12 +80,11 @@ 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) 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 97e29d0e6..d135f9308 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -454,10 +454,10 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const TestComponent = { template: `
- - - - + + + +
`, components: { ChildComponent }, @@ -481,7 +481,13 @@ 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( + '
' + + ' ' + + ' ' + + ' ' + + '' + + '
' + ) }) })