File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ function findAllVNodes(
111
111
if ( node . component ) {
112
112
// match children of the wrapping component
113
113
aggregateChildren ( nodes , node . component . subTree . children )
114
+ aggregateChildren ( nodes , [ node . component . subTree ] )
114
115
}
115
116
if ( node . suspense ) {
116
117
// match children if component is Suspense
@@ -123,7 +124,7 @@ function findAllVNodes(
123
124
aggregateChildren ( nodes , fallbackTree . children )
124
125
}
125
126
}
126
- if ( matches ( node , selector ) ) {
127
+ if ( matches ( node , selector ) && ! matchingNodes . includes ( node ) ) {
127
128
matchingNodes . push ( node )
128
129
}
129
130
}
Original file line number Diff line number Diff line change @@ -226,4 +226,29 @@ describe('findComponent', () => {
226
226
expect ( compB [ 0 ] . vm . $el . querySelector ( '.content' ) . innerHTML ) . toBe ( '1' )
227
227
expect ( compB [ 0 ] . vm . $el . querySelector ( '.content' ) . textContent ) . toBe ( '1' )
228
228
} )
229
+
230
+ // https://github.com/vuejs/vue-test-utils-next/pull/188
231
+ const slotComponent = defineComponent ( {
232
+ name : 'slotA' ,
233
+ template : '<div><slot /><slot name="b" /></div>'
234
+ } )
235
+ const SlotMain = defineComponent ( {
236
+ name : 'SlotMain' ,
237
+ template :
238
+ '<slot-component><comp-b /><comp-b /><comp-b /><comp-c v-slot:b /></slot-component>' ,
239
+ components : { slotComponent, compB, compC }
240
+ } )
241
+ const SlotApp = defineComponent ( {
242
+ name : 'SlotApp' ,
243
+ template : `<slot-main />` ,
244
+ components : { SlotMain }
245
+ } )
246
+
247
+ it ( 'finds components with slots which will be compiled to `{ default: () => [children] }`' , ( ) => {
248
+ const wrapper = mount ( SlotApp )
249
+ expect ( wrapper . findComponent ( slotComponent ) . exists ( ) ) . toBe ( true )
250
+ expect ( wrapper . findComponent ( compB ) . exists ( ) ) . toBe ( true )
251
+ expect ( wrapper . findComponent ( compC ) . exists ( ) ) . toBe ( true )
252
+ expect ( wrapper . findComponent ( SlotMain ) . exists ( ) ) . toBe ( true )
253
+ } )
229
254
} )
You can’t perform that action at this time.
0 commit comments