@@ -33,10 +33,18 @@ class MockIntersectionObserver {
3333 }
3434}
3535
36- // The visibility observer is registered from an idle callback, which falls back
37- // to a short timeout in happy-dom.
36+ // The visibility observer is registered `onNuxtReady` and then from an idle
37+ // callback, both falling back to short timeouts in happy-dom. Positive checks
38+ // poll for the observer, negative ones give the same chain time to run.
3839function idle ( ) {
39- return new Promise ( resolve => setTimeout ( resolve , 10 ) )
40+ return new Promise ( resolve => setTimeout ( resolve , 50 ) )
41+ }
42+
43+ function waitForObserver ( ) {
44+ return vi . waitFor ( ( ) => {
45+ expect ( MockIntersectionObserver . instances ) . toHaveLength ( 1 )
46+ return MockIntersectionObserver . instances [ 0 ] !
47+ } )
4048}
4149
4250describe ( 'Link prefetch' , ( ) => {
@@ -96,9 +104,7 @@ describe('Link prefetch', () => {
96104 wrapper = await mountSuspended ( Link , { props : { to : '/about' } , slots : { default : ( ) => 'About' } } )
97105 const link = wrapper . get ( 'a' ) . element
98106
99- await idle ( )
100-
101- const observer = MockIntersectionObserver . instances [ 0 ] !
107+ const observer = await waitForObserver ( )
102108 expect ( observer . observed ) . toEqual ( [ link ] )
103109 expect ( spy ) . not . toHaveBeenCalled ( )
104110
0 commit comments