@@ -10,8 +10,11 @@ configure({ asyncUtilTimeout: 5000 });
1010
1111// Track all timers created during tests to clean them up
1212const activeTimers = new Set < ReturnType < typeof setTimeout > > ( ) ;
13+ const activeIntervals = new Set < ReturnType < typeof setInterval > > ( ) ;
1314const originalSetTimeout = global . setTimeout ;
1415const originalClearTimeout = global . clearTimeout ;
16+ const originalSetInterval = global . setInterval ;
17+ const originalClearInterval = global . clearInterval ;
1518
1619// Wrap setTimeout to track all timers
1720global . setTimeout = ( ( callback : any , delay ?: any , ...args : any [ ] ) => {
@@ -28,15 +31,34 @@ global.clearTimeout = ((timerId?: ReturnType<typeof setTimeout>) => {
2831 }
2932} ) as typeof clearTimeout ;
3033
34+ // Wrap setInterval the same way so libraries like @formkit /auto-animate
35+ // (which polls via setInterval and calls requestAnimationFrame inside it)
36+ // cannot leak callbacks past the test environment teardown.
37+ global . setInterval = ( ( callback : any , delay ?: any , ...args : any [ ] ) => {
38+ const intervalId = originalSetInterval ( callback , delay , ...args ) ;
39+ activeIntervals . add ( intervalId ) ;
40+ return intervalId ;
41+ } ) as typeof setInterval ;
42+
43+ global . clearInterval = ( ( intervalId ?: ReturnType < typeof setInterval > ) => {
44+ if ( intervalId ) {
45+ activeIntervals . delete ( intervalId ) ;
46+ originalClearInterval ( intervalId ) ;
47+ }
48+ } ) as typeof clearInterval ;
49+
3150beforeEach ( ( ) => {
3251 activeTimers . clear ( ) ;
52+ activeIntervals . clear ( ) ;
3353} ) ;
3454
3555afterEach ( ( ) => {
3656 cleanup ( ) ;
37- // Clear all tracked timers to prevent post-test execution
57+ // Clear all tracked timers/intervals to prevent post-test execution
3858 activeTimers . forEach ( timerId => originalClearTimeout ( timerId ) ) ;
3959 activeTimers . clear ( ) ;
60+ activeIntervals . forEach ( intervalId => originalClearInterval ( intervalId ) ) ;
61+ activeIntervals . clear ( ) ;
4062} ) ;
4163
4264// Store the original method
0 commit comments