@@ -54,74 +54,33 @@ global.advanceUntilValue = (spring, value) => {
5454 } )
5555}
5656
57- global . getFrames = ( arg : SpringValue | Controller ) => {
58- const { frames, testIdle, reset } = getTestHelpers ( arg )
59- // expect(spring.animation.values).not.toEqual([])
57+ global . getFrames = ( ctrl : SpringValue | Controller ) => {
58+ const frames : any [ ] = [ ]
6059
6160 let steps = 0
62- while ( ! testIdle ( ) ) {
61+ while ( ! ctrl . idle ) {
6362 mockRaf . step ( )
63+ frames . push ( ctrl . get ( ) )
6464 if ( ++ steps > 1e5 ) {
6565 throw Error ( 'Infinite loop detected' )
6666 }
6767 }
6868
69- reset ( )
7069 return frames
7170}
7271
7372global . getAsyncFrames = async ctrl => {
74- const { frames, testIdle , reset } = getTestHelpers ( ctrl )
73+ const frames : any [ ] = [ ]
7574
7675 let steps = 0
77- while ( ! testIdle ( ) ) {
76+ while ( ! ctrl . idle ) {
7877 mockRaf . step ( )
78+ frames . push ( ctrl . get ( ) )
7979 await Promise . resolve ( )
8080 if ( ++ steps > 1e5 ) {
8181 throw Error ( 'Infinite loop detected' )
8282 }
8383 }
8484
85- reset ( )
8685 return frames
8786}
88-
89- function getTestHelpers ( arg : Controller < any > | SpringValue < any > ) {
90- const frames : any [ ] = [ ]
91-
92- const ctrl = arg instanceof Controller ? arg : null
93- if ( ctrl ) {
94- const { onFrame } = ctrl [ '_state' ]
95- ctrl [ '_state' ] . onFrame = ( frame : any ) => {
96- frames . push ( frame )
97- if ( onFrame ) onFrame ( frame )
98- }
99- return {
100- frames,
101- testIdle : ( ) =>
102- ! ctrl [ '_state' ] . promise &&
103- Object . values ( ctrl . springs ) . every ( spring => spring ! . idle ) ,
104- reset ( ) {
105- ctrl [ '_state' ] . onFrame = onFrame
106- } ,
107- }
108- }
109-
110- const spring = arg instanceof SpringValue ? arg : null
111- if ( spring ) {
112- const onChange = spring [ '_onChange' ]
113- spring [ '_onChange' ] = ( value , idle ) => {
114- frames . push ( value )
115- onChange . call ( spring , value , idle )
116- }
117- return {
118- frames,
119- testIdle : ( ) => spring . idle && ! spring [ '_state' ] . promise ,
120- reset ( ) {
121- spring [ '_onChange' ] = onChange
122- } ,
123- }
124- }
125-
126- throw Error ( 'Invalid argument' )
127- }
0 commit comments