11import { renderHook , act } from '@testing-library/react'
22import useAnimationFrame from '../src/useAnimationFrame.js'
3+ import { describe , it , beforeAll , afterAll , vi , expect } from 'vitest'
34
45describe ( 'useAnimationFrame' , ( ) => {
56 let rafSpy , rafCancelSpy
67
78 beforeAll ( ( ) => {
8- rafSpy = jest
9+ rafSpy = vi
910 . spyOn ( window , 'requestAnimationFrame' )
1011 . mockImplementation ( ( cb ) => {
1112 return setTimeout ( ( ) => cb ( 1 ) ) as any
1213 } )
1314
14- rafCancelSpy = jest
15+ rafCancelSpy = vi
1516 . spyOn ( window , 'cancelAnimationFrame' )
1617 . mockImplementation ( ( handle ) => {
1718 clearTimeout ( handle )
@@ -24,48 +25,48 @@ describe('useAnimationFrame', () => {
2425 } )
2526
2627 it ( 'should requestAnimationFrame' , ( ) => {
27- jest . useFakeTimers ( )
28+ vi . useFakeTimers ( )
2829
29- let spy = jest . fn ( )
30+ let spy = vi . fn ( )
3031
3132 const { result } = renderHook ( useAnimationFrame )
3233
3334 act ( ( ) => result . current ! . request ( spy ) )
3435
3536 expect ( spy ) . not . toHaveBeenCalled ( )
3637
37- jest . runAllTimers ( )
38+ vi . runAllTimers ( )
3839
3940 expect ( spy ) . toHaveBeenCalledTimes ( 1 )
4041 } )
4142
4243 it ( 'should cancel a request' , ( ) => {
43- jest . useFakeTimers ( )
44+ vi . useFakeTimers ( )
4445
45- let spy = jest . fn ( )
46+ let spy = vi . fn ( )
4647 const { result } = renderHook ( useAnimationFrame )
4748
4849 act ( ( ) => {
4950 result . current . request ( spy )
5051
5152 result . current . cancel ( )
5253 } )
53- jest . runAllTimers ( )
54+ vi . runAllTimers ( )
5455
5556 expect ( spy ) . toHaveBeenCalledTimes ( 0 )
5657 } )
5758
5859 it ( 'should cancel a request on unmount' , ( ) => {
59- jest . useFakeTimers ( )
60+ vi . useFakeTimers ( )
6061
61- let spy = jest . fn ( )
62+ let spy = vi . fn ( )
6263 const { result, unmount } = renderHook ( useAnimationFrame )
6364
6465 act ( ( ) => result . current ! . request ( spy ) )
6566
6667 unmount ( )
6768
68- jest . runAllTimers ( )
69+ vi . runAllTimers ( )
6970
7071 expect ( spy ) . toHaveBeenCalledTimes ( 0 )
7172 } )
0 commit comments