5
5
throwError ,
6
6
camelize ,
7
7
capitalize ,
8
- hyphenate ,
9
- keys
8
+ hyphenate
9
+ // keys
10
10
} from '../shared/util'
11
11
import {
12
12
componentNeedsCompiling ,
@@ -80,25 +80,42 @@ function resolveOptions(component, _Vue) {
80
80
return options
81
81
}
82
82
83
- function getScopedSlotRenderFunctions ( ctx : any ) : Array < string > {
84
- // In Vue 2.6+ a new v-slot syntax was introduced
85
- // scopedSlots are now saved in parent._vnode.data.scopedSlots
86
- // We filter out the _normalized and $stable key
87
- if (
88
- ctx &&
89
- ctx . $options &&
90
- ctx . $options . parent &&
91
- ctx . $options . parent . _vnode &&
92
- ctx . $options . parent . _vnode . data &&
93
- ctx . $options . parent . _vnode . data . scopedSlots
94
- ) {
95
- const slotKeys : Array < string > = ctx.$options.parent._vnode.data.scopedSlots
96
- return keys(slotKeys).filter(x => x !== '_normalized' && x !== '$stable' )
97
- }
98
-
99
- return [ ]
83
+ function getAttributes (
84
+ functional : boolean ,
85
+ functionalCtx : any ,
86
+ componentCtx
87
+ ) : Object {
88
+ return functional
89
+ ? {
90
+ ...functionalCtx . props ,
91
+ ...functionalCtx . data . attrs ,
92
+ class : createClassString (
93
+ functionalCtx . data . staticClass ,
94
+ functionalCtx . data . class
95
+ )
96
+ }
97
+ : componentCtx . $props
100
98
}
101
99
100
+ // function getScopedSlotRenderFunctions(ctx: any): Array<string> {
101
+ // // In Vue 2.6+ a new v-slot syntax was introduced
102
+ // // scopedSlots are now saved in parent._vnode.data.scopedSlots
103
+ // // We filter out the _normalized and $stable key
104
+ // if (
105
+ // ctx &&
106
+ // ctx.$options &&
107
+ // ctx.$options.parent &&
108
+ // ctx.$options.parent._vnode &&
109
+ // ctx.$options.parent._vnode.data &&
110
+ // ctx.$options.parent._vnode.data.scopedSlots
111
+ // ) {
112
+ // const slotKeys: Array<string> = ctx.$options.parent._vnode.data.scopedSlots
113
+ // return keys(slotKeys).filter(x => x !== '_normalized' && x !== '$stable')
114
+ // }
115
+ //
116
+ // return []
117
+ // }
118
+
102
119
export function createStubFromComponent (
103
120
originalComponent : Component ,
104
121
name : string ,
@@ -120,19 +137,7 @@ export function createStubFromComponent(
120
137
$_vueTestUtils_original : originalComponent ,
121
138
$_doNotStubChildren : true ,
122
139
render ( h , context ) {
123
- const attrs = componentOptions . functional
124
- ? {
125
- ...context . props ,
126
- ...context . data . attrs ,
127
- class : createClassString (
128
- context . data . staticClass ,
129
- context . data . class
130
- )
131
- }
132
- : {
133
- ...this . $props
134
- }
135
-
140
+ const attrs = getAttributes ( componentOptions . functional , context , this )
136
141
const slots = context ? context . slots ( ) : this . _renderProxy . $slots
137
142
138
143
// ensure consistent ordering of slots (default first, then alphabetical)
@@ -145,13 +150,31 @@ export function createStubFromComponent(
145
150
: slotNameA . localeCompare ( slotNameB )
146
151
)
147
152
148
- const children = sortedSlotEntries . map ( ( [ slotName , slotChildren ] ) =>
153
+ const sortedSlots = sortedSlotEntries . map ( ( [ slotName , slotChildren ] ) =>
149
154
slotName === 'default'
150
155
? slotChildren
151
156
: h ( 'template-stub' , { attrs : { slot : slotName } } , slotChildren )
152
157
)
153
158
154
- return h ( tagName , { attrs } , children )
159
+ // let children
160
+ // if (context) {
161
+ // children = sortedSlots
162
+ // } else if (this.$options._renderChildren) {
163
+ // children = this.$options._renderChildren
164
+ // } else {
165
+ // children = getScopedSlotRenderFunctions(this).map(x =>
166
+ // this.$options.parent._vnode.data.scopedSlots[x]()
167
+ // )
168
+ // }
169
+
170
+ return h (
171
+ tagName ,
172
+ {
173
+ attrs,
174
+ ref : componentOptions . functional ? context . data . ref : undefined
175
+ } ,
176
+ sortedSlots
177
+ )
155
178
}
156
179
}
157
180
}
0 commit comments