Skip to content

Commit 359c805

Browse files
committed
fix: add support for uncompiled extended components
1 parent 9609d1e commit 359c805

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/lib/compile-template.js

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

55
export function compileTemplate (component: Component) {
6-
Object.assign(component, compileToFunctions(component.template))
6+
if (component.extends) {
7+
compileTemplate(component.extends)
8+
}
9+
if (component.template) {
10+
Object.assign(component, compileToFunctions(component.template))
11+
}
712
}

src/lib/create-instance.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export default function createConstructor (
4343
stubComponents(component, mountingOptions.stubs)
4444
}
4545

46-
if (!component.render && component.template && !component.functional) {
46+
if (!component.render &&
47+
(component.template || component.extends) &&
48+
!component.functional) {
4749
compileTemplate(component)
4850
}
4951

test/unit/specs/mount.spec.js

+31
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,37 @@ describe('mount', () => {
5656
}
5757
})
5858

59+
it('handles uncompiled extended Vue component', () => {
60+
const BaseComponent = {
61+
template: '<div />'
62+
}
63+
const TestComponent = {
64+
extends: BaseComponent
65+
}
66+
const wrapper = mount(TestComponent)
67+
expect(wrapper.findAll('div').length).to.equal(1)
68+
})
69+
70+
it('handles nested uncompiled extended Vue component', () => {
71+
const BaseComponent = {
72+
template: '<div />'
73+
}
74+
const TestComponentA = {
75+
extends: BaseComponent
76+
}
77+
const TestComponentB = {
78+
extends: TestComponentA
79+
}
80+
const TestComponentC = {
81+
extends: TestComponentB
82+
}
83+
const TestComponentD = {
84+
extends: TestComponentC
85+
}
86+
const wrapper = mount(TestComponentD)
87+
expect(wrapper.findAll('div').length).to.equal(1)
88+
})
89+
5990
it('does not use cached component', () => {
6091
ComponentWithMixin.methods.someMethod = sinon.stub()
6192
mount(ComponentWithMixin)

0 commit comments

Comments
 (0)