File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,11 @@ export class DOMWrapper<NodeType extends Node> extends BaseWrapper<NodeType> {
22
22
}
23
23
24
24
getCurrentComponent ( ) {
25
- return this . element . __vueParentComponent
25
+ let component = this . element . __vueParentComponent
26
+ while ( component ?. parent ?. vnode . el === this . element ) {
27
+ component = component . parent
28
+ }
29
+ return component
26
30
}
27
31
28
32
find < K extends keyof HTMLElementTagNameMap > (
Original file line number Diff line number Diff line change @@ -510,5 +510,34 @@ describe('findComponent', () => {
510
510
. classes ( 'inside' )
511
511
) . toBe ( true )
512
512
} )
513
+
514
+ it ( 'finds top component when searching from nested node' , ( ) => {
515
+ const DeepNestedComponent = defineComponent ( {
516
+ template : '<div class="deep-nested"></div>'
517
+ } )
518
+
519
+ const NestedComponent = defineComponent ( {
520
+ components : { DeepNestedComponent } ,
521
+ template : '<deep-nested-component />'
522
+ } )
523
+
524
+ const RootComponent = defineComponent ( {
525
+ components : { NestedComponent } ,
526
+ template : '<nested-component />'
527
+ } )
528
+
529
+ const wrapper = mount ( RootComponent )
530
+ expect (
531
+ wrapper . find ( '.deep-nested' ) . findComponent ( DeepNestedComponent ) . exists ( )
532
+ ) . toBe ( true )
533
+
534
+ expect (
535
+ wrapper . find ( '.deep-nested' ) . findComponent ( NestedComponent ) . exists ( )
536
+ ) . toBe ( true )
537
+
538
+ expect (
539
+ wrapper . find ( '.deep-nested' ) . findComponent ( RootComponent ) . exists ( )
540
+ ) . toBe ( true )
541
+ } )
513
542
} )
514
543
} )
You can’t perform that action at this time.
0 commit comments