Skip to content

Commit 0371793

Browse files
kuitoseddyerburgh
authored andcommitted
fix: keep the overrides prototype information of component (#856)
1 parent c747cd6 commit 0371793

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Diff for: packages/create-instance/create-instance.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ export default function createInstance (
126126
component.options._base = _Vue
127127
}
128128

129-
const Constructor = vueVersion < 2.3 && typeof component === 'function'
129+
// when component constructed by Vue.extend,
130+
// use its own extend method to keep component information
131+
const Constructor = typeof component === 'function'
130132
? component.extend(instanceOptions)
131133
: _Vue.extend(component).extend(instanceOptions)
132134

Diff for: test/specs/mount.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,28 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
153153
expect(stub).not.called
154154
})
155155

156+
it('overrides component prototype', () => {
157+
const mountSpy = sinon.spy()
158+
const destroySpy = sinon.spy()
159+
const Component = Vue.extend({})
160+
const { $mount: originalMount, $destroy: originalDestroy } = Component.prototype
161+
Component.prototype.$mount = function (...args) {
162+
mountSpy()
163+
originalMount.apply(this, args)
164+
return this
165+
}
166+
Component.prototype.$destroy = function () {
167+
originalDestroy.apply(this)
168+
destroySpy()
169+
}
170+
171+
const wrapper = mount(Component)
172+
expect(mountSpy).called
173+
expect(destroySpy).not.called
174+
wrapper.destroy()
175+
expect(destroySpy).called
176+
})
177+
156178
// Problems accessing options of twice extended components in Vue < 2.3
157179
itDoNotRunIf(vueVersion < 2.3, 'compiles extended components', () => {
158180
const TestComponent = Vue.component('test-component', {

0 commit comments

Comments
 (0)