Skip to content

Commit 879c31a

Browse files
committed
fix: extend inlined constructor functions
1 parent dc58676 commit 879c31a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

packages/create-instance/create-instance.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createSlotVNodes } from './create-slot-vnodes'
44
import addMocks from './add-mocks'
55
import { addEventLogger } from './log-events'
66
import { addStubs } from './add-stubs'
7+
import { patchRender } from './patch-render'
78
import { throwError, vueVersion } from 'shared/util'
89
import {
910
compileTemplate,
@@ -60,6 +61,7 @@ export default function createInstance (
6061
addEventLogger(_Vue)
6162
addMocks(options.mocks, _Vue)
6263
addStubs(component, options.stubs, _Vue, options.shouldProxy)
64+
patchRender(_Vue)
6365

6466
if (
6567
(component.options && component.options.functional) ||
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { addHook } from './add-hook'
2+
3+
// This is used to extend component constructors
4+
// used directly in a render function
5+
// see #
6+
export function patchRender (_Vue) {
7+
addHook(_Vue.options, 'beforeCreate', function () {
8+
const createElementSave = this.$createElement
9+
this.$createElement = function (el, ...args) {
10+
if (
11+
typeof el === 'function' &&
12+
el.super !== _Vue &&
13+
!el.options.$_vueTestUtils_original
14+
) {
15+
el = _Vue.extend(el.options)
16+
}
17+
return createElementSave(el, ...args)
18+
}
19+
})
20+
}

test/specs/mounting-options/localVue.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ describeWithMountingMethods('options.localVue', mountingMethod => {
155155
})
156156
})
157157

158+
it('is applied to inline constructor functions', () => {
159+
const ChildComponent = Vue.extend({
160+
render (h) {
161+
h('p', this.$route.params)
162+
}
163+
})
164+
const TestComponent = {
165+
render: h => h(ChildComponent)
166+
}
167+
const localVue = createLocalVue()
168+
localVue.prototype.$route = {}
169+
const wrapper = mountingMethod(TestComponent, {
170+
localVue
171+
})
172+
expect(wrapper.findAll(ChildComponent).length).to.equal(1)
173+
})
174+
158175
itRunIf(
159176
vueVersion < 2.3,
160177
'throws an error if used with an extended component in Vue 2.3', () => {

0 commit comments

Comments
 (0)