@@ -9,11 +9,12 @@ describe('useAnimationLoop', () => {
99 } ) ;
1010 } ) ;
1111
12- it ( 'should not execute the callback function when enabled is not passed ' , async ( ) => {
12+ it ( 'should not execute the callback function when enabled is set to false ' , async ( ) => {
1313 const spy = jest . fn ( ) ;
14+
1415 renderHook (
1516 ( { callback } ) => {
16- useAnimationLoop ( callback ) ;
17+ useAnimationLoop ( callback , false ) ;
1718 } ,
1819 {
1920 initialProps : {
@@ -29,35 +30,34 @@ describe('useAnimationLoop', () => {
2930
3031 it ( 'should execute the callback function when useAnimationLoop is enabled' , async ( ) => {
3132 const spy = jest . fn ( ) ;
33+
3234 renderHook (
33- ( { callback, enabled } ) => {
34- useAnimationLoop ( callback , enabled ) ;
35+ ( { callback } ) => {
36+ useAnimationLoop ( callback ) ;
3537 } ,
3638 {
3739 initialProps : {
3840 callback : spy ,
39- enabled : true ,
4041 } ,
4142 } ,
4243 ) ;
4344
44- expect ( spy ) . toBeCalledTimes ( 0 ) ;
4545 await waitFor ( ( ) => {
4646 expect ( spy ) . toBeCalled ( ) ;
4747 } ) ;
4848 } ) ;
4949
50- it ( 'should execute another callback function when it is passed to useAnimationLoop and not execute previously passed callback function' , async ( ) => {
50+ it ( 'should not execute previous callback function when callback function is updated ' , async ( ) => {
5151 const spyFirstRender = jest . fn ( ) ;
5252 const spySecondRender = jest . fn ( ) ;
53+
5354 const { rerender } = renderHook (
54- ( { callback, enabled } ) => {
55- useAnimationLoop ( callback , enabled ) ;
55+ ( { callback } ) => {
56+ useAnimationLoop ( callback ) ;
5657 } ,
5758 {
5859 initialProps : {
5960 callback : spyFirstRender ,
60- enabled : true ,
6161 } ,
6262 } ,
6363 ) ;
@@ -67,16 +67,18 @@ describe('useAnimationLoop', () => {
6767 expect ( spySecondRender ) . toBeCalledTimes ( 0 ) ;
6868 } ) ;
6969
70- rerender ( { callback : spySecondRender , enabled : true } ) ;
70+ rerender ( { callback : spySecondRender } ) ;
7171 const amountOfCalls = spyFirstRender . mock . calls . length ;
72+
7273 await waitFor ( ( ) => {
7374 expect ( spyFirstRender ) . toBeCalledTimes ( amountOfCalls ) ;
7475 expect ( spySecondRender ) . toBeCalled ( ) ;
7576 } ) ;
7677 } ) ;
7778
78- it ( 'should execute the callback function when useAnimationLoop is enabled on the first render and should not execute the callback function when useAnimationLoop is disabled on the second render ' , async ( ) => {
79+ it ( 'should execute the callback function when useAnimationLoop is enabled and should not execute the callback function when useAnimationLoop is disabled' , async ( ) => {
7980 const spy = jest . fn ( ) ;
81+
8082 const { rerender } = renderHook (
8183 ( { callback, enabled } ) => {
8284 useAnimationLoop ( callback , enabled ) ;
@@ -89,13 +91,16 @@ describe('useAnimationLoop', () => {
8991 } ,
9092 ) ;
9193
92- waitFor ( ( ) => {
94+ await waitFor ( ( ) => {
9395 expect ( spy ) . toBeCalled ( ) ;
9496 } ) ;
9597
9698 rerender ( { callback : spy , enabled : false } ) ;
97- waitFor ( ( ) => {
98- expect ( spy ) . toBeCalledTimes ( 0 ) ;
99+
100+ const amountOfCalls = spy . mock . calls . length ;
101+
102+ await waitFor ( ( ) => {
103+ expect ( spy ) . toBeCalledTimes ( amountOfCalls ) ;
99104 } ) ;
100105 } ) ;
101106} ) ;
0 commit comments