@@ -110,37 +110,48 @@ export function createStubFromComponent(
110
110
// ignoreElements does not exist in Vue 2.0.x
111
111
if ( Vue . config . ignoredElements ) {
112
112
Vue . config . ignoredElements . push ( tagName )
113
+ if ( Vue . config . ignoredElements . indexOf ( 'template-stub' ) === - 1 ) {
114
+ Vue . config . ignoredElements . push ( 'template-stub' )
115
+ }
113
116
}
114
117
115
118
return {
116
119
...getCoreProperties ( componentOptions ) ,
117
120
$_vueTestUtils_original : originalComponent ,
118
121
$_doNotStubChildren : true ,
119
122
render ( h , context ) {
120
- return h (
121
- tagName ,
122
- {
123
- ref : componentOptions . functional ? context . data . ref : undefined ,
124
- attrs : componentOptions . functional
125
- ? {
126
- ...context . props ,
127
- ...context . data . attrs ,
128
- class : createClassString (
129
- context . data . staticClass ,
130
- context . data . class
131
- )
132
- }
133
- : {
134
- ...this . $props
135
- }
136
- } ,
137
- context
138
- ? context . children
139
- : this . $options . _renderChildren ||
140
- getScopedSlotRenderFunctions ( this ) . map ( x =>
141
- this . $options . parent . _vnode . data . scopedSlots [ x ] ( )
142
- )
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
+
136
+ const slots = context ? context . slots ( ) : this . _renderProxy . $slots
137
+
138
+ // ensure consistent ordering of slots (default first, then alphabetical)
139
+ const sortedSlotEntries = Object . entries ( slots )
140
+ sortedSlotEntries . sort ( ( [ slotNameA ] , [ slotNameB ] ) =>
141
+ slotNameA === 'default'
142
+ ? - 1
143
+ : slotNameB === 'default'
144
+ ? 1
145
+ : slotNameA . localeCompare ( slotNameB )
146
+ )
147
+
148
+ const children = sortedSlotEntries . map ( ( [ slotName , slotChildren ] ) =>
149
+ slotName === 'default'
150
+ ? slotChildren
151
+ : h ( 'template-stub' , { attrs : { slot : slotName } } , slotChildren )
143
152
)
153
+
154
+ return h ( tagName , { attrs } , children )
144
155
}
145
156
}
146
157
}
0 commit comments