From db6d4f1b480e72a926ff7ef5ec9649984274cfb0 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Mon, 21 May 2018 18:33:07 +0100 Subject: [PATCH 1/2] test: improve spec name --- packages/shared/compile-template.js | 8 ++++---- packages/shared/validators.js | 4 +++- test/specs/mount.spec.js | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/shared/compile-template.js b/packages/shared/compile-template.js index 0aba6297d..e88d40cf9 100644 --- a/packages/shared/compile-template.js +++ b/packages/shared/compile-template.js @@ -3,6 +3,10 @@ import { compileToFunctions } from 'vue-template-compiler' export function compileTemplate (component: Component) { + if (component.template) { + Object.assign(component, compileToFunctions(component.template)) + } + if (component.components) { Object.keys(component.components).forEach((c) => { const cmp = component.components[c] @@ -19,8 +23,4 @@ export function compileTemplate (component: Component) { if (component.extendOptions && !component.options.render) { compileTemplate(component.options) } - - if (component.template) { - Object.assign(component, compileToFunctions(component.template)) - } } diff --git a/packages/shared/validators.js b/packages/shared/validators.js index ceaad8643..da7cc7b65 100644 --- a/packages/shared/validators.js +++ b/packages/shared/validators.js @@ -41,7 +41,9 @@ export function isVueComponent (component: any) { export function componentNeedsCompiling (component: Component) { return component && !component.render && - (component.template || component.extends) && + (component.template || + component.extends || + component.extendOptions) && !component.functional } diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index 67997efe9..c3d10dbde 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -131,6 +131,14 @@ describeRunIf(process.env.TEST_ENV !== 'node', expect(wrapper.html()).to.equal(`
foo
`) }) + it('compiles extended components', () => { + const TestComponent = Vue.component('test-component', { + template: '
' + }) + const wrapper = mount(TestComponent) + expect(wrapper.html()).to.equal(`
`) + }) + it('logs if component is extended', () => { const msg = '[vue-test-utils]: an extended child component ChildComponent has been modified to ensure it has the correct instance properties. This means it is not possible to find the component with a component selector. To find the component, you must stub it manually using the stubs mounting option.' const ChildComponent = Vue.extend({ From 0330bb514b46b298cd36675b7a9142e0c2789fe8 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Mon, 21 May 2018 22:16:12 +0100 Subject: [PATCH 2/2] test: do not run for Vue < 2.3 --- test/specs/mount.spec.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index c3d10dbde..1f1061bb6 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -5,7 +5,10 @@ import Component from '~resources/components/component.vue' import ComponentWithProps from '~resources/components/component-with-props.vue' import ComponentWithMixin from '~resources/components/component-with-mixin.vue' import { injectSupported, vueVersion } from '~resources/utils' -import { describeRunIf } from 'conditional-specs' +import { + describeRunIf, + itDoNotRunIf +} from 'conditional-specs' describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { @@ -131,13 +134,15 @@ describeRunIf(process.env.TEST_ENV !== 'node', expect(wrapper.html()).to.equal(`
foo
`) }) - it('compiles extended components', () => { - const TestComponent = Vue.component('test-component', { - template: '
' + // Problems accessing options of twice extended components in Vue < 2.3 + itDoNotRunIf(vueVersion < 2.3, + 'compiles extended components', () => { + const TestComponent = Vue.component('test-component', { + template: '
' + }) + const wrapper = mount(TestComponent) + expect(wrapper.html()).to.equal(`
`) }) - const wrapper = mount(TestComponent) - expect(wrapper.html()).to.equal(`
`) - }) it('logs if component is extended', () => { const msg = '[vue-test-utils]: an extended child component ChildComponent has been modified to ensure it has the correct instance properties. This means it is not possible to find the component with a component selector. To find the component, you must stub it manually using the stubs mounting option.'