Skip to content

Commit 73980c4

Browse files
kuitoseddyerburgh
authored andcommitted
fix: reconcile the overridden prototype of component with _Vue mixins (#889)
1 parent 0193483 commit 73980c4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

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

129+
function getExtendedComponent (component, instanceOptions) {
130+
const extendedComponent = component.extend(instanceOptions)
131+
// to keep the possible overridden prototype and _Vue mixins,
132+
// we need change the proto chains manually
133+
// @see https://github.com/vuejs/vue-test-utils/pull/856
134+
// code below equals to
135+
// `extendedComponent.prototype.__proto__.__proto__ = _Vue.prototype`
136+
const extendedComponentProto =
137+
Object.getPrototypeOf(extendedComponent.prototype)
138+
Object.setPrototypeOf(extendedComponentProto, _Vue.prototype)
139+
140+
return extendedComponent
141+
}
142+
129143
// extend component from _Vue to add properties and mixins
130-
const Constructor = typeof component === 'function' && vueVersion < 2.3
131-
? component.extend(instanceOptions)
144+
const Constructor = typeof component === 'function'
145+
? getExtendedComponent(component, instanceOptions)
132146
: _Vue.extend(component).extend(instanceOptions)
133147

134148
Object.keys(instanceOptions.components || {}).forEach(key => {

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

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

156-
it.skip('overrides component prototype', () => {
156+
it('overrides component prototype', () => {
157157
const mountSpy = sinon.spy()
158158
const destroySpy = sinon.spy()
159159
const Component = Vue.extend({})
160160
const { $mount: originalMount, $destroy: originalDestroy } = Component.prototype
161161
Component.prototype.$mount = function (...args) {
162-
mountSpy()
163162
originalMount.apply(this, args)
163+
mountSpy()
164164
return this
165165
}
166166
Component.prototype.$destroy = function () {

0 commit comments

Comments
 (0)