@@ -17,7 +17,7 @@ import {
1717 ComponentHandler ,
1818 HandlerResolverComponentProps ,
1919} from "./utils" ;
20- import delay from "./utils/delay " ;
20+ import awaitNextFrame from "./utils/awaitNextFrame " ;
2121
2222describe ( "Vanilla tests" , ( ) => {
2323 it ( "should render with undefined sizes at first" , async ( ) => {
@@ -55,7 +55,7 @@ describe("Vanilla tests", () => {
5555 assertRenderCount ( 3 ) ;
5656
5757 setSize ( { width : 321 , height : 456 } ) ;
58- await delay ( 50 ) ;
58+ await awaitNextFrame ( ) ;
5959 assertSize ( { width : 321 , height : 456 } ) ;
6060 assertRenderCount ( 4 ) ;
6161 } ) ;
@@ -143,7 +143,7 @@ describe("Vanilla tests", () => {
143143 handler . assertDefaultSize ( ) ;
144144
145145 // Actual measurement
146- await delay ( 50 ) ;
146+ await awaitNextFrame ( ) ;
147147 handler . assertSize ( { width : 100 , height : 200 } ) ;
148148 } ) ;
149149
@@ -188,12 +188,12 @@ describe("Vanilla tests", () => {
188188 handler . assertDefaultSize ( ) ;
189189
190190 // Div 1 measurement
191- await delay ( 50 ) ;
191+ await awaitNextFrame ( ) ;
192192 handler . assertSize ( { width : 100 , height : 200 } ) ;
193193
194194 // Div 2 measurement
195195 switchRefs ( ) ;
196- await delay ( 50 ) ;
196+ await awaitNextFrame ( ) ;
197197 handler . assertSize ( { width : 150 , height : 250 } ) ;
198198 } ) ;
199199
@@ -204,7 +204,7 @@ describe("Vanilla tests", () => {
204204 handler . assertDefaultSize ( ) ;
205205
206206 handler . setSize ( { width : 100 , height : 100 } ) ;
207- await delay ( 50 ) ;
207+ await awaitNextFrame ( ) ;
208208 handler . assertSize ( { width : 100 , height : 100 } ) ;
209209 } ) ;
210210
@@ -214,18 +214,18 @@ describe("Vanilla tests", () => {
214214 handler . assertDefaultSize ( ) ;
215215
216216 // Default render + first measurement
217- await delay ( 50 ) ;
217+ await awaitNextFrame ( ) ;
218218 handler . assertRenderCount ( 2 ) ;
219219
220220 handler . setSize ( { width : 100 , height : 102 } ) ;
221- await delay ( 50 ) ;
221+ await awaitNextFrame ( ) ;
222222 handler . assertSize ( { width : 100 , height : 102 } ) ;
223223 handler . assertRenderCount ( 3 ) ;
224224
225225 // Shouldn't trigger on subpixel values that are rounded to be the same as the
226226 // previous size
227227 handler . setSize ( { width : 100.4 , height : 102.4 } ) ;
228- await delay ( 50 ) ;
228+ await awaitNextFrame ( ) ;
229229 handler . assertSize ( { width : 100 , height : 102 } ) ;
230230 handler . assertRenderCount ( 3 ) ;
231231 } ) ;
@@ -309,7 +309,7 @@ describe("Vanilla tests", () => {
309309
310310 // Since no refs were passed in with an element to be measured, the hook should
311311 // stay on the defaults
312- await delay ( 50 ) ;
312+ await awaitNextFrame ( ) ;
313313 handler . assertDefaultSize ( ) ;
314314 } ) ;
315315
@@ -322,9 +322,9 @@ describe("Vanilla tests", () => {
322322 ) ;
323323
324324 handler . setSize ( { width : 100 , height : 200 } ) ;
325- await delay ( 50 ) ;
325+ await awaitNextFrame ( ) ;
326326 handler . setSize ( { width : 101 , height : 201 } ) ;
327- await delay ( 50 ) ;
327+ await awaitNextFrame ( ) ;
328328
329329 // Should stay at default as width/height is not passed to the hook response
330330 // when an onResize callback is given
@@ -371,25 +371,25 @@ describe("Vanilla tests", () => {
371371
372372 // Establishing a default, which'll be measured when the resize handler is set.
373373 setSize ( { width : 1 , height : 1 } ) ;
374- await delay ( 50 ) ;
374+ await awaitNextFrame ( ) ;
375375
376376 assertRenderCount ( 1 ) ;
377377
378378 changeOnResizeHandler ( ( size : ObservedSize ) => observations1 . push ( size ) ) ;
379- await delay ( 50 ) ;
379+ await awaitNextFrame ( ) ;
380380 setSize ( { width : 1 , height : 2 } ) ;
381- await delay ( 50 ) ;
381+ await awaitNextFrame ( ) ;
382382 setSize ( { width : 3 , height : 4 } ) ;
383383
384384 assertRenderCount ( 2 ) ;
385385
386- await delay ( 50 ) ;
386+ await awaitNextFrame ( ) ;
387387 changeOnResizeHandler ( ( size : ObservedSize ) => observations2 . push ( size ) ) ;
388- await delay ( 50 ) ;
388+ await awaitNextFrame ( ) ;
389389 setSize ( { width : 5 , height : 6 } ) ;
390- await delay ( 50 ) ;
390+ await awaitNextFrame ( ) ;
391391 setSize ( { width : 7 , height : 8 } ) ;
392- await delay ( 50 ) ;
392+ await awaitNextFrame ( ) ;
393393
394394 assertRenderCount ( 3 ) ;
395395
0 commit comments