@@ -354,44 +354,52 @@ describe('scriptGoogleMapsOverlayView', () => {
354354 // resolved a position. That caused unexpected map panning on initial mount
355355 // and remount. The fix gates the rAF scheduling on `open !== false` and
356356 // re-checks `open` + `overlayPosition` inside the callback before panning.
357+ //
358+ // We mock `requestAnimationFrame` to fire its callback synchronously so the
359+ // panMapToFitOverlay → panBy path is exercised within the test, then assert
360+ // on `panBy` (the actual user-visible side effect). Spying on rAF directly
361+ // is unreliable in the Nuxt/happy-dom environment, which itself schedules
362+ // background rAF calls during mount.
357363
358364 let rafSpy : ReturnType < typeof vi . spyOn >
359365
360366 beforeEach ( ( ) => {
361- rafSpy = vi . spyOn ( globalThis , 'requestAnimationFrame' )
367+ rafSpy = vi . spyOn ( globalThis , 'requestAnimationFrame' ) . mockImplementation ( ( ( cb : FrameRequestCallback ) => {
368+ cb ( 0 )
369+ return 0
370+ } ) as typeof globalThis . requestAnimationFrame )
362371 } )
363372
364373 afterEach ( ( ) => {
365374 rafSpy . mockRestore ( )
366375 } )
367376
368- it ( 'does not schedule pan-on-open when overlay starts closed (defaultOpen=false)' , async ( ) => {
377+ it ( 'does not pan when overlay starts closed (defaultOpen=false)' , async ( ) => {
369378 const mocks = createOverlayMocks ( )
370379 await mountOverlay (
371380 { position : { lat : 10 , lng : 20 } , defaultOpen : false } ,
372381 mocks ,
373382 )
374383
375- expect ( rafSpy ) . not . toHaveBeenCalled ( )
376384 expect ( mocks . mockMap . panBy ) . not . toHaveBeenCalled ( )
377385 } )
378386
379- it ( 'does not schedule pan-on-open when controlled :open is false on mount' , async ( ) => {
387+ it ( 'does not pan when controlled :open is false on mount' , async ( ) => {
380388 const mocks = createOverlayMocks ( )
381389 await mountOverlay (
382390 { position : { lat : 10 , lng : 20 } , open : false } ,
383391 mocks ,
384392 )
385393
386- expect ( rafSpy ) . not . toHaveBeenCalled ( )
387394 expect ( mocks . mockMap . panBy ) . not . toHaveBeenCalled ( )
388395 } )
389396
390397 it ( 'schedules pan-on-open when overlay starts open with a position' , async ( ) => {
391398 const mocks = createOverlayMocks ( )
392399 await mountOverlay ( { position : { lat : 10 , lng : 20 } } , mocks )
393400
394- // The guard allows the rAF to be scheduled when the happy path applies
401+ // Happy path: rAF callback fires synchronously via the mock, then
402+ // panMapToFitOverlay runs panBy off the (mock) bounding rects.
395403 expect ( rafSpy ) . toHaveBeenCalled ( )
396404 } )
397405
@@ -402,7 +410,6 @@ describe('scriptGoogleMapsOverlayView', () => {
402410 mocks ,
403411 )
404412
405- expect ( rafSpy ) . not . toHaveBeenCalled ( )
406413 expect ( mocks . mockMap . panBy ) . not . toHaveBeenCalled ( )
407414 } )
408415 } )
0 commit comments