|
1 | 1 | // @flow
|
2 | 2 |
|
| 3 | +import Vue from 'vue' |
3 | 4 | import { createSlotVNodes } from './create-slot-vnodes'
|
4 | 5 | import addMocks from './add-mocks'
|
5 | 6 | import { addEventLogger } from './log-events'
|
@@ -109,10 +110,35 @@ export default function createInstance (
|
109 | 110 | component.options._base = _Vue
|
110 | 111 | }
|
111 | 112 |
|
| 113 | + function getRootVueProto (obj) { |
| 114 | + while (obj) { |
| 115 | + if (Object.getPrototypeOf(obj) === Vue.prototype) { |
| 116 | + return obj |
| 117 | + } |
| 118 | + |
| 119 | + obj = Object.getPrototypeOf(obj) |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + function getExtendedComponent (component, instanceOptions) { |
| 124 | + // extend _Vue to merge the mixins on _Vue |
| 125 | + const extendedComponent = component.extend(_Vue).extend(instanceOptions) |
| 126 | + |
| 127 | + // cache subclass constructor |
| 128 | + component.options._Ctor[extendedComponent.cid] = extendedComponent |
| 129 | + |
| 130 | + // to keep the possible overridden prototype and _Vue mocks on prototype, |
| 131 | + // we need change the proto chains manually |
| 132 | + // @see https://github.com/vuejs/vue-test-utils/pull/856 |
| 133 | + const root = getRootVueProto(extendedComponent.prototype) |
| 134 | + Object.setPrototypeOf(root, _Vue.prototype) |
| 135 | + |
| 136 | + return extendedComponent |
| 137 | + } |
| 138 | + |
112 | 139 | // extend component from _Vue to add properties and mixins
|
113 |
| - // extend does not work correctly for sub class components in Vue < 2.2 |
114 |
| - const Constructor = typeof component === 'function' && vueVersion < 2.3 |
115 |
| - ? component.extend(instanceOptions) |
| 140 | + const Constructor = typeof component === 'function' |
| 141 | + ? getExtendedComponent(component, instanceOptions) |
116 | 142 | : _Vue.extend(component).extend(instanceOptions)
|
117 | 143 |
|
118 | 144 | // Keep reference to component mount was called with
|
|
0 commit comments