33import { createSlotVNodes } from './create-slot-vnodes'
44import addMocks from './add-mocks'
55import { addEventLogger } from './log-events'
6- import { createComponentStubs } from 'shared/stub-components '
7- import { throwError , warn , vueVersion } from 'shared/util'
6+ import { addStubs } from './add-stubs '
7+ import { throwError , vueVersion } from 'shared/util'
88import { compileTemplate } from 'shared/compile-template'
99import { isRequiredComponent } from 'shared/validators'
1010import extractInstanceOptions from './extract-instance-options'
1111import createFunctionalComponent from './create-functional-component'
1212import { componentNeedsCompiling , isPlainObject } from 'shared/validators'
1313import { validateSlots } from './validate-slots'
1414import createScopedSlots from './create-scoped-slots'
15+ import { extendExtendedComponents } from './extend-extended-components'
1516
1617function compileTemplateForSlots ( slots : Object ) : void {
1718 Object . keys ( slots ) . forEach ( key => {
@@ -33,21 +34,14 @@ export default function createInstance (
3334 // Remove cached constructor
3435 delete component . _Ctor
3536
36- // mounting options are vue-test-utils specific
37- //
3837 // instance options are options that are passed to the
3938 // root instance when it's instantiated
40- //
41- // component options are the root components options
42- const componentOptions = typeof component === 'function'
43- ? component . extendOptions
44- : component
45-
4639 const instanceOptions = extractInstanceOptions ( options )
4740
48- if ( options . mocks ) {
49- addMocks ( options . mocks , _Vue )
50- }
41+ addEventLogger ( _Vue )
42+ addMocks ( options . mocks , _Vue )
43+ addStubs ( component , options . stubs , _Vue )
44+
5145 if (
5246 ( component . options && component . options . functional ) ||
5347 component . functional
@@ -63,8 +57,6 @@ export default function createInstance (
6357 compileTemplate ( component )
6458 }
6559
66- addEventLogger ( _Vue )
67-
6860 // Replace globally registered components with components extended
6961 // from localVue. This makes sure the beforeMount mixins to add stubs
7062 // is applied to globally registered components.
@@ -78,77 +70,25 @@ export default function createInstance (
7870 }
7971 }
8072
81- const stubComponents = createComponentStubs (
82- component . components ,
83- // $FlowIgnore
84- options . stubs
73+ extendExtendedComponents (
74+ component ,
75+ _Vue ,
76+ options . logModifiedComponents ,
77+ instanceOptions . components
8578 )
86- if ( options . stubs ) {
87- instanceOptions . components = {
88- ...instanceOptions . components ,
89- ...stubComponents
90- }
91- }
92- function addStubComponentsMixin ( ) {
93- Object . assign (
94- this . $options . components ,
95- stubComponents
96- )
97- }
98- _Vue . mixin ( {
99- beforeMount : addStubComponentsMixin ,
100- // beforeCreate is for components created in node, which
101- // never mount
102- beforeCreate : addStubComponentsMixin
103- } )
104- Object . keys ( componentOptions . components || { } ) . forEach ( c => {
105- if (
106- componentOptions . components [ c ] . extendOptions &&
107- ! instanceOptions . components [ c ]
108- ) {
109- if ( options . logModifiedComponents ) {
110- warn (
111- `an extended child component <${ c } > has been modified ` +
112- `to ensure it has the correct instance properties. ` +
113- `This means it is not possible to find the component ` +
114- `with a component selector. To find the component, ` +
115- `you must stub it manually using the stubs mounting ` +
116- `option.`
117- )
118- }
119- instanceOptions . components [ c ] = _Vue . extend (
120- componentOptions . components [ c ]
121- )
122- }
123- } )
12479
12580 if ( component . options ) {
12681 component . options . _base = _Vue
12782 }
12883
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-
14384 // extend component from _Vue to add properties and mixins
144- const Constructor = typeof component === 'function'
145- ? getExtendedComponent ( component , instanceOptions )
85+ // extend does not work correctly for sub class components in Vue < 2.2
86+ const Constructor = typeof component === 'function' && vueVersion < 2.3
87+ ? component . extend ( instanceOptions )
14688 : _Vue . extend ( component ) . extend ( instanceOptions )
14789
148- Object . keys ( instanceOptions . components || { } ) . forEach ( key => {
149- Constructor . component ( key , instanceOptions . components [ key ] )
150- _Vue . component ( key , instanceOptions . components [ key ] )
151- } )
90+ // Keep reference to component mount was called with
91+ Constructor . _vueTestUtilsRoot = component
15292
15393 if ( options . slots ) {
15494 compileTemplateForSlots ( options . slots )
0 commit comments