Skip to content

Commit e1fb4a0

Browse files
authored
fix: compile extended components (#637)
1 parent 5b5319d commit e1fb4a0

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

packages/shared/compile-template.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import { compileToFunctions } from 'vue-template-compiler'
44

55
export function compileTemplate (component: Component) {
6+
if (component.template) {
7+
Object.assign(component, compileToFunctions(component.template))
8+
}
9+
610
if (component.components) {
711
Object.keys(component.components).forEach((c) => {
812
const cmp = component.components[c]
@@ -19,8 +23,4 @@ export function compileTemplate (component: Component) {
1923
if (component.extendOptions && !component.options.render) {
2024
compileTemplate(component.options)
2125
}
22-
23-
if (component.template) {
24-
Object.assign(component, compileToFunctions(component.template))
25-
}
2626
}

packages/shared/validators.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export function isVueComponent (component: any) {
4141
export function componentNeedsCompiling (component: Component) {
4242
return component &&
4343
!component.render &&
44-
(component.template || component.extends) &&
44+
(component.template ||
45+
component.extends ||
46+
component.extendOptions) &&
4547
!component.functional
4648
}
4749

test/specs/mount.spec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import Component from '~resources/components/component.vue'
55
import ComponentWithProps from '~resources/components/component-with-props.vue'
66
import ComponentWithMixin from '~resources/components/component-with-mixin.vue'
77
import { injectSupported, vueVersion } from '~resources/utils'
8-
import { describeRunIf } from 'conditional-specs'
8+
import {
9+
describeRunIf,
10+
itDoNotRunIf
11+
} from 'conditional-specs'
912

1013
describeRunIf(process.env.TEST_ENV !== 'node',
1114
'mount', () => {
@@ -131,6 +134,16 @@ describeRunIf(process.env.TEST_ENV !== 'node',
131134
expect(wrapper.html()).to.equal(`<div>foo</div>`)
132135
})
133136

137+
// Problems accessing options of twice extended components in Vue < 2.3
138+
itDoNotRunIf(vueVersion < 2.3,
139+
'compiles extended components', () => {
140+
const TestComponent = Vue.component('test-component', {
141+
template: '<div></div>'
142+
})
143+
const wrapper = mount(TestComponent)
144+
expect(wrapper.html()).to.equal(`<div></div>`)
145+
})
146+
134147
it('logs if component is extended', () => {
135148
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.'
136149
const ChildComponent = Vue.extend({

0 commit comments

Comments
 (0)