From 72a47c4b49ebbdb265c2ce13372b628b54566857 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 5 May 2018 21:22:30 +0100 Subject: [PATCH 1/4] fix: overwrites registered components for stubs --- packages/create-instance/create-instance.js | 8 +++++++- test/resources/utils.js | 20 ++++++++++++++++++++ test/specs/mounting-options/stubs.spec.js | 16 ++++++++++++++++ test/specs/wrapper/setProps.spec.js | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index d401e6a60..e705d8f27 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -59,14 +59,20 @@ export default function createInstance ( const instanceOptions = { ...options } deleteoptions(instanceOptions) + const stubComponents = createComponentStubs(component.components, options.stubs) + if (options.stubs) { instanceOptions.components = { ...instanceOptions.components, // $FlowIgnore - ...createComponentStubs(component.components, options.stubs) + ...stubComponents } } + Object.keys(stubComponents).forEach(c => { + vue.component(c, stubComponents[c]) + }) + const vm = new Constructor(instanceOptions) addAttrs(vm, options.attrs) diff --git a/test/resources/utils.js b/test/resources/utils.js index 548bf2fd9..249ca9ee5 100644 --- a/test/resources/utils.js +++ b/test/resources/utils.js @@ -80,6 +80,14 @@ export function itSkipIf (predicate, spec, cb) { } } +itSkipIf.only = (predicate, spec, cb) => { + if (predicate) { + it.skip(spec, cb) + } else { + it.only(spec, cb) + } +} + export function itDoNotRunIf (predicate, spec, cb) { if (predicate) { () => {} @@ -88,8 +96,20 @@ export function itDoNotRunIf (predicate, spec, cb) { } } +itDoNotRunIf.only = (predicate, spec, cb) => { + if (!predicate) { + it.only(spec, cb) + } +} + export function describeIf (predicate, spec, cb) { if (predicate) { describe(spec, cb) } } + +describeIf.only = (predicate, spec, cb) => { + if (predicate) { + describe(spec, cb) + } +} diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index 87c8ba9fd..d3b83dfd6 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -248,6 +248,22 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { expect(HTML).to.contain('') }) + itDoNotRunIf( + mountingMethod.name === 'shallow', + 'stubs on child components', () => { + const TestComponent = { + template: '' + } + + const wrapper = mountingMethod({ + components: { 'test-component': TestComponent }, + template: '' + }, { + stubs: ['transition'] + }) + expect(wrapper.find('span').exists()).to.equal(false) + }) + it('converts config to array if stubs is an array', () => { const localVue = createLocalVue() config.stubs['time-component'] = '

' diff --git a/test/specs/wrapper/setProps.spec.js b/test/specs/wrapper/setProps.spec.js index 1f7524b4f..d490c320e 100644 --- a/test/specs/wrapper/setProps.spec.js +++ b/test/specs/wrapper/setProps.spec.js @@ -105,7 +105,7 @@ describeWithShallowAndMount('setProps', (mountingMethod) => { expect(wrapper.text()).to.equal('There is no message yet') }) - it.only('runs watchers correctly', () => { + it('runs watchers correctly', () => { const TestComponent = { template: `

{{ stringified }} From 864eba3f9c715a87c73a34b72cd307706e93bbf3 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 5 May 2018 21:36:12 +0100 Subject: [PATCH 2/4] test: fix flow error --- packages/create-instance/create-instance.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index e705d8f27..94e35e7a0 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -59,6 +59,7 @@ export default function createInstance ( const instanceOptions = { ...options } deleteoptions(instanceOptions) + // $FlowIgnore const stubComponents = createComponentStubs(component.components, options.stubs) if (options.stubs) { From 89e2403b13f3705f76f4ad5c774a594bb59a8e8e Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 5 May 2018 21:36:37 +0100 Subject: [PATCH 3/4] linting error --- packages/create-instance/create-instance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index 94e35e7a0..3eff2ceff 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -59,7 +59,7 @@ export default function createInstance ( const instanceOptions = { ...options } deleteoptions(instanceOptions) - // $FlowIgnore + // $FlowIgnore const stubComponents = createComponentStubs(component.components, options.stubs) if (options.stubs) { From 04f4e43e453222f67589569d5c91e09e50952310 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 5 May 2018 21:58:40 +0100 Subject: [PATCH 4/4] test: fix node test --- test/specs/mounting-options/stubs.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index d3b83dfd6..94bcd1d19 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -249,7 +249,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { }) itDoNotRunIf( - mountingMethod.name === 'shallow', + mountingMethod.name === 'shallow' || + mountingMethod.name === 'renderToString', 'stubs on child components', () => { const TestComponent = { template: ''