From 1f4876e19f0edbd86a67f50024e247e8db8e4dbd Mon Sep 17 00:00:00 2001 From: Edd Yerburgh Date: Sat, 29 Dec 2018 10:36:21 +0000 Subject: [PATCH] fix: add stub without modifying (#1085) --- .../create-instance/create-component-stubs.js | 7 +--- test/specs/mounting-options/stubs.spec.js | 40 +++++++++++++++---- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/packages/create-instance/create-component-stubs.js b/packages/create-instance/create-component-stubs.js index c3fbd94a1..ededc3b1e 100644 --- a/packages/create-instance/create-component-stubs.js +++ b/packages/create-instance/create-component-stubs.js @@ -167,13 +167,8 @@ export function createStubsFromStubsObject ( if (componentNeedsCompiling(stub)) { compileTemplate(stub) } - const name = originalComponents[stubName] && - originalComponents[stubName].name - acc[stubName] = { - name, - ...stub - } + acc[stubName] = stub return acc }, {}) diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index 7f5a565d6..9abac1bf3 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -64,18 +64,18 @@ describeWithMountingMethods('options.stub', mountingMethod => { mountingMethod.name === 'renderToString', 'replaces component with a component', () => { + const mounted = sinon.stub() + const Stub = { + template: '
', + mounted + } const wrapper = mountingMethod(ComponentWithChild, { stubs: { - ChildComponent: { - render: h => h('time'), - mounted () { - console.info('stubbed') - } - } + ChildComponent: Stub } }) - expect(wrapper.findAll(Component).length).to.equal(1) - expect(info.calledWith('stubbed')).to.equal(true) + expect(wrapper.findAll(Stub).length).to.equal(1) + expect(mounted).calledOnce } ) @@ -567,4 +567,28 @@ describeWithMountingMethods('options.stub', mountingMethod => { ) expect(HTML).to.contain('h1') }) + + itDoNotRunIf( + mountingMethod.name === 'renderToString', + 'uses original component stub', () => { + const Stub = { + template: '
' + } + const ToStub = { + template: '
' + } + const TestComponent = { + template: '
', + components: { + ToStub + } + } + const wrapper = mountingMethod(TestComponent, { + stubs: { + ToStub: Stub + } + }) + expect(wrapper.find(ToStub).exists()).to.be.false + expect(wrapper.find(Stub).exists()).to.be.true + }) })