33import { createSlotVNodes } from './create-slot-vnodes'
44import addMocks from './add-mocks'
55import { addEventLogger } from './log-events'
6- import { createComponentStubs } from 'shared/stub-components '
6+ import { addStubs } from './add-stubs '
77import { throwError , vueVersion } from 'shared/util'
88import { compileTemplate } from 'shared/compile-template'
99import { isRequiredComponent } from 'shared/validators'
@@ -34,18 +34,15 @@ export default function createInstance (
3434 // Remove cached constructor
3535 delete component . _Ctor
3636
37- // mounting options are vue-test-utils specific
38- //
37+
3938 // instance options are options that are passed to the
4039 // root instance when it's instantiated
41- //
42- // component options are the root components options
40+ const instanceOptions = extractInstanceOptions ( options )
4341
44- const instanceOptions = extractInstanceOptions ( options )
42+ addEventLogger ( _Vue )
43+ addMocks ( options . mocks , _Vue )
44+ addStubs ( component , options . stubs , _Vue )
4545
46- if ( options . mocks ) {
47- addMocks ( options . mocks , _Vue )
48- }
4946 if (
5047 ( component . options && component . options . functional ) ||
5148 component . functional
@@ -61,7 +58,6 @@ export default function createInstance (
6158 compileTemplate ( component )
6259 }
6360
64- addEventLogger ( _Vue )
6561
6662 // Replace globally registered components with components extended
6763 // from localVue. This makes sure the beforeMount mixins to add stubs
@@ -76,68 +72,22 @@ export default function createInstance (
7672 }
7773 }
7874
79- const stubComponents = createComponentStubs (
80- component . components ,
81- // $FlowIgnore
82- options . stubs
83- )
84-
8575 extendExtendedComponents (
8676 component ,
8777 _Vue ,
8878 options . logModifiedComponents ,
8979 instanceOptions . components
9080 )
9181
92- // stub components should override every component defined in a component
93- if ( options . stubs ) {
94- instanceOptions . components = {
95- ...instanceOptions . components ,
96- ...stubComponents
97- }
98- }
99- function addStubComponentsMixin ( ) {
100- Object . assign (
101- this . $options . components ,
102- stubComponents
103- )
104- }
105- _Vue . mixin ( {
106- beforeMount : addStubComponentsMixin ,
107- // beforeCreate is for components created in node, which
108- // never mount
109- beforeCreate : addStubComponentsMixin
110- } )
111-
11282 if ( component . options ) {
11383 component . options . _base = _Vue
11484 }
11585
116- function getExtendedComponent ( component , instanceOptions ) {
117- const extendedComponent = component . extend ( instanceOptions )
118- // to keep the possible overridden prototype and _Vue mixins,
119- // we need change the proto chains manually
120- // @see https://github.com/vuejs/vue-test-utils/pull/856
121- // code below equals to
122- // `extendedComponent.prototype.__proto__.__proto__ = _Vue.prototype`
123- const extendedComponentProto =
124- Object . getPrototypeOf ( extendedComponent . prototype )
125- Object . setPrototypeOf ( extendedComponentProto , _Vue . prototype )
126-
127- return extendedComponent
128- }
129-
13086 // extend component from _Vue to add properties and mixins
131- const Constructor = typeof component === 'function'
132- ? getExtendedComponent ( component , instanceOptions )
133- : _Vue . extend ( component ) . extend ( instanceOptions )
87+ const Constructor = _Vue . extend ( component ) . extend ( instanceOptions )
13488
13589 Constructor . _vueTestUtilsRoot = component
13690
137- Object . keys ( instanceOptions . components || { } ) . forEach ( c => {
138- Constructor . component ( c , instanceOptions . components [ c ] )
139- } )
140-
14191 if ( options . slots ) {
14292 compileTemplateForSlots ( options . slots )
14393 // $FlowIgnore
0 commit comments