diff --git a/packages/shared/stub-components.js b/packages/shared/stub-components.js index 697e0eaf2..9358fcee0 100644 --- a/packages/shared/stub-components.js +++ b/packages/shared/stub-components.js @@ -62,10 +62,17 @@ function createStubFromString ( } function createBlankStub (originalComponent: Component) { + const name = `${originalComponent.name}-stub` + + // ignoreElements does not exist in Vue 2.0.x + if (Vue.config.ignoredElements) { + Vue.config.ignoredElements.push(name) + } + return { ...getCoreProperties(originalComponent), render (h) { - return h(`${originalComponent.name}-stub`) + return h(name) } } } @@ -131,10 +138,6 @@ export function createComponentStubs ( } } } - // ignoreElements does not exist in Vue 2.0.x - if (Vue.config.ignoredElements) { - Vue.config.ignoredElements.push(`${stub}-stub`) - } }) } return components @@ -148,11 +151,6 @@ function stubComponents (components: Object, stubbedComponents: Object) { components[component].name = component } stubbedComponents[component] = createBlankStub(components[component]) - - // ignoreElements does not exist in Vue 2.0.x - if (Vue.config.ignoredElements) { - Vue.config.ignoredElements.push(`${components[component].name}-stub`) - } }) } @@ -163,6 +161,8 @@ export function createComponentStubsForAll (component: Component): Object { stubComponents(component.components, stubbedComponents) } + stubbedComponents[component.name] = createBlankStub(component) + let extended = component.extends // Loop through extended component chains to stub all child components diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index 441afe32c..d6baa1c82 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -9,18 +9,18 @@ import ComponentWithoutName from '~resources/components/component-without-name.v import ComponentAsAClassWithChild from '~resources/components/component-as-a-class-with-child.vue' import RecursiveComponent from '~resources/components/recursive-component.vue' import { vueVersion } from '~resources/utils' -import { describeRunIf } from 'conditional-specs' +import { describeRunIf, itDoNotRunIf } from 'conditional-specs' describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { - let info - beforeEach(() => { - info = sinon.stub(console, 'info') + sinon.stub(console, 'info') + sinon.stub(console, 'error') }) afterEach(() => { - info.restore() + console.info.restore() + console.error.restore() }) it('returns new VueWrapper of Vue localVue if no options are passed', () => { @@ -61,7 +61,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', localVue.component('registered-component', ComponentWithLifecycleHooks) mount(TestComponent, { localVue }) - expect(info.callCount).to.equal(4) + expect(console.info.callCount).to.equal(4) }) it('stubs globally registered components', () => { @@ -72,12 +72,52 @@ describeRunIf(process.env.TEST_ENV !== 'node', shallowMount(Component) mount(Component) - expect(info.callCount).to.equal(4) - }) + expect(console.info.callCount).to.equal(4) + }) + + itDoNotRunIf( + vueVersion < 2.1, + 'adds stubbed components to ignored elements', () => { + const TestComponent = { + template: ` +