@@ -117,14 +117,14 @@ describe('ConsentBannerElement', () => {
117117
118118 expect ( window . document . activeElement ) . toBe ( wrapper )
119119
120- await new Promise < void > ( resolve => {
121- setTimeout ( resolve , 0 )
122- } )
123- const allowBtn = window . document . querySelector (
124- '.consent-modal__btn-allow '
120+ // Tab from the modal wrapper moves focus to the first focusable element.
121+ wrapper ! . dispatchEvent ( new window . KeyboardEvent ( 'keydown' , { key : 'Tab' , bubbles : true } ) )
122+
123+ const closeBtn = window . document . querySelector (
124+ '.consent-modal__close-btn '
125125 ) as HTMLButtonElement | null
126- expect ( allowBtn ) . not . toBeNull ( )
127- expect ( window . document . activeElement ) . toBe ( allowBtn )
126+ expect ( closeBtn ) . not . toBeNull ( )
127+ expect ( window . document . activeElement ) . toBe ( closeBtn )
128128 } )
129129 } )
130130
@@ -181,7 +181,7 @@ describe('ConsentBannerElement', () => {
181181 const navigateSpy = vi . spyOn ( bannerCtor , 'navigateToUrl' ) . mockImplementation ( ( ) => { } )
182182
183183 try {
184- customizeLink ! . dispatchEvent ( new window . MouseEvent ( 'click' , { bubbles : true } ) )
184+ customizeLink ! . dispatchEvent ( new window . MouseEvent ( 'click' , { bubbles : true , cancelable : true } ) )
185185
186186 expect ( navigateSpy ) . toHaveBeenCalledTimes ( 1 )
187187 expect ( navigateSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '/consent' ) )
0 commit comments