@@ -45,7 +45,7 @@ describe('dom-utils', () => {
4545 } ) ;
4646
4747 describe ( 'getClosestElement' , ( ) => {
48- let element ;
48+ let element , node ;
4949
5050 const tag = defineCE (
5151 class ShadowElement extends HTMLElement {
@@ -63,28 +63,32 @@ describe('dom-utils', () => {
6363 } ,
6464 ) ;
6565
66- it ( 'should return the closest element matching the selector within the shadow root' , ( ) => {
66+ it ( 'should return closest element matching selector within shadow root' , ( ) => {
6767 element = fixtureSync ( `<${ tag } ></${ tag } >` ) ;
68- const node = element . shadowRoot . querySelector ( '.child' ) ;
68+ node = element . shadowRoot . querySelector ( '.child' ) ;
6969 const expected = element . shadowRoot . querySelector ( '.parent-2' ) ;
7070 expect ( getClosestElement ( '.parent' , node ) ) . to . equal ( expected ) ;
7171 } ) ;
7272
73- it ( 'should return the closest element matching the selector across the shadow root' , ( ) => {
73+ it ( 'should return closest element matching selector across shadow root' , ( ) => {
7474 element = fixtureSync ( `<div class="wrapper"><${ tag } ></${ tag } ></div>` ) ;
75- const node = element . querySelector ( tag ) . shadowRoot . querySelector ( '.parent' ) ;
75+
76+ node = element . querySelector ( tag ) . shadowRoot ;
77+ expect ( getClosestElement ( '.wrapper' , node ) ) . to . equal ( element ) ;
78+
79+ node = element . querySelector ( tag ) . shadowRoot . querySelector ( '.parent' ) ;
7680 expect ( getClosestElement ( '.wrapper' , node ) ) . to . equal ( element ) ;
7781 } ) ;
7882
7983 it ( 'should return null when no closest element is found' , ( ) => {
8084 element = fixtureSync ( `<${ tag } ></${ tag } >` ) ;
81- const node = element . shadowRoot . querySelector ( '.child' ) ;
85+ node = element . shadowRoot . querySelector ( '.child' ) ;
8286 expect ( getClosestElement ( '.not-existing-class' , node ) ) . to . be . null ;
8387 } ) ;
8488
85- it ( 'should return the passed element if it matches the selector' , ( ) => {
89+ it ( 'should return passed element if it matches selector' , ( ) => {
8690 element = fixtureSync ( `<${ tag } ></${ tag } >` ) ;
87- const node = element . shadowRoot . querySelector ( '.child' ) ;
91+ node = element . shadowRoot . querySelector ( '.child' ) ;
8892 expect ( getClosestElement ( '.child' , node ) ) . to . equal ( node ) ;
8993 } ) ;
9094 } ) ;
0 commit comments