3
3
import { createSlotVNodes } from './create-slot-vnodes'
4
4
import addMocks from './add-mocks'
5
5
import { addEventLogger } from './log-events'
6
- import { createComponentStubs } from 'shared/stub-components '
6
+ import { addStubs } from './add-stubs '
7
7
import { throwError , vueVersion } from 'shared/util'
8
8
import { compileTemplate } from 'shared/compile-template'
9
9
import { isRequiredComponent } from 'shared/validators'
@@ -34,18 +34,15 @@ export default function createInstance (
34
34
// Remove cached constructor
35
35
delete component . _Ctor
36
36
37
- // mounting options are vue-test-utils specific
38
- //
37
+
39
38
// instance options are options that are passed to the
40
39
// root instance when it's instantiated
41
- //
42
- // component options are the root components options
40
+ const instanceOptions = extractInstanceOptions ( options )
43
41
44
- const instanceOptions = extractInstanceOptions ( options )
42
+ addEventLogger ( _Vue )
43
+ addMocks ( options . mocks , _Vue )
44
+ addStubs ( component , options . stubs , _Vue )
45
45
46
- if ( options . mocks ) {
47
- addMocks ( options . mocks , _Vue )
48
- }
49
46
if (
50
47
( component . options && component . options . functional ) ||
51
48
component . functional
@@ -61,7 +58,6 @@ export default function createInstance (
61
58
compileTemplate ( component )
62
59
}
63
60
64
- addEventLogger ( _Vue )
65
61
66
62
// Replace globally registered components with components extended
67
63
// from localVue. This makes sure the beforeMount mixins to add stubs
@@ -76,68 +72,22 @@ export default function createInstance (
76
72
}
77
73
}
78
74
79
- const stubComponents = createComponentStubs (
80
- component . components ,
81
- // $FlowIgnore
82
- options . stubs
83
- )
84
-
85
75
extendExtendedComponents (
86
76
component ,
87
77
_Vue ,
88
78
options . logModifiedComponents ,
89
79
instanceOptions . components
90
80
)
91
81
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
-
112
82
if ( component . options ) {
113
83
component . options . _base = _Vue
114
84
}
115
85
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
-
130
86
// 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 )
134
88
135
89
Constructor . _vueTestUtilsRoot = component
136
90
137
- Object . keys ( instanceOptions . components || { } ) . forEach ( c => {
138
- Constructor . component ( c , instanceOptions . components [ c ] )
139
- } )
140
-
141
91
if ( options . slots ) {
142
92
compileTemplateForSlots ( options . slots )
143
93
// $FlowIgnore
0 commit comments