From 33a6731cae814b804ba923abbd8c65d5812126d0 Mon Sep 17 00:00:00 2001 From: Edd Yerburgh Date: Sat, 5 May 2018 22:40:24 +0100 Subject: [PATCH] fix: overwrites registered components for stubs (#585) --- packages/create-instance/create-instance.js | 9 ++++++++- test/resources/utils.js | 20 ++++++++++++++++++++ test/specs/mounting-options/stubs.spec.js | 17 +++++++++++++++++ test/specs/wrapper/setProps.spec.js | 2 +- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index d401e6a60..3eff2ceff 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -59,14 +59,21 @@ export default function createInstance ( const instanceOptions = { ...options } deleteoptions(instanceOptions) + // $FlowIgnore + 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..94bcd1d19 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -248,6 +248,23 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { expect(HTML).to.contain('') }) + itDoNotRunIf( + mountingMethod.name === 'shallow' || + mountingMethod.name === 'renderToString', + '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 }}