From c38812d5a3b4a3ded275a9ea348f44420fab44bf Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 29 Dec 2018 08:59:26 +0000 Subject: [PATCH 1/4] fix: add stub without modifying --- .../create-instance/create-component-stubs.js | 7 +--- test/specs/mounting-options/stubs.spec.js | 37 +++++++++++++++---- 2 files changed, 31 insertions(+), 13 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..b884574d4 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -64,17 +64,18 @@ describeWithMountingMethods('options.stub', mountingMethod => { mountingMethod.name === 'renderToString', 'replaces component with a component', () => { + const Stub = { + render: h => h('time'), + mounted () { + console.info('stubbed') + } + } 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(wrapper.findAll(Stub).length).to.equal(1) expect(info.calledWith('stubbed')).to.equal(true) } ) @@ -567,4 +568,26 @@ describeWithMountingMethods('options.stub', mountingMethod => { ) expect(HTML).to.contain('h1') }) + + it('uses original component stub', () => { + const Stub = { + template: '
' + } + const ToStub = { + template: '
' + } + const TestComponent = { + template: '
', + components: { + ToStub + } + } + const w = mountingMethod(TestComponent, { + stubs: { + ToStub: Stub + } + }) + expect(w.find(ToStub).exists()).to.be.false + expect(w.find(Stub).exists()).to.be.true + }) }) From 69f01191681307db48919e82d2824af705f77a7b Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 29 Dec 2018 09:20:36 +0000 Subject: [PATCH 2/4] test: only run test for wrapper methods --- test/specs/mounting-options/stubs.spec.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index b884574d4..5300f84d6 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -569,7 +569,9 @@ describeWithMountingMethods('options.stub', mountingMethod => { expect(HTML).to.contain('h1') }) - it('uses original component stub', () => { + itDoNotRunIf( + mountingMethod.name === 'renderToString', + 'uses original component stub', () => { const Stub = { template: '
' } @@ -582,12 +584,12 @@ describeWithMountingMethods('options.stub', mountingMethod => { ToStub } } - const w = mountingMethod(TestComponent, { + const wrapper = mountingMethod(TestComponent, { stubs: { ToStub: Stub } }) - expect(w.find(ToStub).exists()).to.be.false - expect(w.find(Stub).exists()).to.be.true + expect(wrapper.find(ToStub).exists()).to.be.false + expect(wrapper.find(Stub).exists()).to.be.true }) }) From 825f146d5945e42e044b0ecfbb1a2478e2af0779 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 29 Dec 2018 09:22:53 +0000 Subject: [PATCH 3/4] test: fix linting errors --- test/specs/mounting-options/stubs.spec.js | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index 5300f84d6..2e8b7ecce 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -572,24 +572,24 @@ describeWithMountingMethods('options.stub', mountingMethod => { itDoNotRunIf( mountingMethod.name === 'renderToString', 'uses original component stub', () => { - const Stub = { - template: '
' - } - const ToStub = { - template: '
' - } - const TestComponent = { - template: '
', - components: { - ToStub + const Stub = { + template: '
' } - } - const wrapper = mountingMethod(TestComponent, { - stubs: { - ToStub: Stub + 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 }) - expect(wrapper.find(ToStub).exists()).to.be.false - expect(wrapper.find(Stub).exists()).to.be.true - }) }) From c1099fb9f8195d8b5aed36dee9558b366bff6ba4 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 29 Dec 2018 10:01:21 +0000 Subject: [PATCH 4/4] test: refactor test --- test/specs/mounting-options/stubs.spec.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index 2e8b7ecce..9abac1bf3 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -64,11 +64,10 @@ describeWithMountingMethods('options.stub', mountingMethod => { mountingMethod.name === 'renderToString', 'replaces component with a component', () => { + const mounted = sinon.stub() const Stub = { - render: h => h('time'), - mounted () { - console.info('stubbed') - } + template: '
', + mounted } const wrapper = mountingMethod(ComponentWithChild, { stubs: { @@ -76,7 +75,7 @@ describeWithMountingMethods('options.stub', mountingMethod => { } }) expect(wrapper.findAll(Stub).length).to.equal(1) - expect(info.calledWith('stubbed')).to.equal(true) + expect(mounted).calledOnce } )