File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed
packages/@headlessui-react/src/test-utils Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -130,11 +130,29 @@ executeTimeline.fullTransition = (duration: number) => {
130130 ]
131131}
132132
133- // Assuming that we run at 60 frames per second
134- let frame = 1000 / 60
133+ let state : {
134+ before : number
135+ fps : number
136+ handle : ReturnType < typeof requestAnimationFrame > | null
137+ } = {
138+ before : Date . now ( ) ,
139+ fps : 0 ,
140+ handle : null ,
141+ }
142+
143+ state . handle = requestAnimationFrame ( function loop ( ) {
144+ let now = Date . now ( )
145+ state . fps = Math . round ( 1000 / ( now - state . before ) )
146+ state . before = now
147+ state . handle = requestAnimationFrame ( loop )
148+ } )
149+
150+ afterAll ( ( ) => {
151+ if ( state . handle ) cancelAnimationFrame ( state . handle )
152+ } )
135153
136- function isWithinFrame ( actual : number , expected : number , frames = 2 ) {
137- let buffer = frame * frames
154+ function isWithinFrame ( actual : number , expected : number ) {
155+ let buffer = state . fps
138156
139157 let min = expected - buffer
140158 let max = expected + buffer
You can’t perform that action at this time.
0 commit comments