From cf9cad290163c0e2175d2aac0318b0eb9fbebcb8 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 22 Dec 2018 12:03:19 +0000 Subject: [PATCH 1/2] fix: keep object prototype when adding stubs --- packages/create-instance/patch-render.js | 5 ++--- test/specs/shallow-mount.spec.js | 25 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/create-instance/patch-render.js b/packages/create-instance/patch-render.js index 4ab5dca47..43387d6a7 100644 --- a/packages/create-instance/patch-render.js +++ b/packages/create-instance/patch-render.js @@ -108,10 +108,9 @@ export function patchRender (_Vue, stubs, stubAllComponents) { const stub = createStubIfNeeded(stubAllComponents, original, _Vue, el) if (stub) { - vm.$options.components = { - ...vm.$options.components, + Object.assign(vm.$options.components, { [el]: stub - } + }) modifiedComponents.add(el) } } diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index d135f9308..0ad4f8c60 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -13,8 +13,8 @@ import { describeRunIf, itDoNotRunIf } from 'conditional-specs' describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { beforeEach(() => { - sinon.stub(console, 'info') - sinon.stub(console, 'error') + sinon.stub(console, 'info').callThrough() + sinon.stub(console, 'error').callThrough() }) afterEach(() => { @@ -490,4 +490,25 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { '' ) }) + + it('does not error when rendering a previously stubbed component', () => { + const ChildComponent = { + render: h => h('div') + } + const TestComponent = { + template: ` +
+ + +
+ `, + components: { + ExtendedComponent: Vue.extend({ render: h => h('div') }), + ChildComponent + } + } + shallowMount(TestComponent) + mount(TestComponent) + expect(console.error).not.called + }) }) From b8bff420a2d609da529e3b0819eed492b6253fcf Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 22 Dec 2018 13:49:28 +0000 Subject: [PATCH 2/2] test: only run on Vue > 2.0 --- test/specs/shallow-mount.spec.js | 35 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index 0ad4f8c60..7dd91b877 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -491,24 +491,29 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { ) }) - it('does not error when rendering a previously stubbed component', () => { - const ChildComponent = { - render: h => h('div') - } - const TestComponent = { - template: ` + itDoNotRunIf( + vueVersion < 2.1, + 'does not error when rendering a previously stubbed component', () => { + const ChildComponent = { + render: h => h('div') + } + const TestComponent = { + template: `
- + + +
`, - components: { - ExtendedComponent: Vue.extend({ render: h => h('div') }), - ChildComponent + components: { + ExtendedComponent: Vue.extend({ render: h => h('div') }), + ChildComponent + } } - } - shallowMount(TestComponent) - mount(TestComponent) - expect(console.error).not.called - }) + shallowMount(TestComponent) + mount(TestComponent) + expect(console.error) + .not.calledWith(sinon.match('Unknown custom element')) + }) })