@@ -17,7 +17,7 @@ import {
17
17
ComponentHandler ,
18
18
HandlerResolverComponentProps ,
19
19
} from "./utils" ;
20
- import delay from "./utils/delay " ;
20
+ import awaitNextFrame from "./utils/awaitNextFrame " ;
21
21
22
22
describe ( "Vanilla tests" , ( ) => {
23
23
it ( "should render with undefined sizes at first" , async ( ) => {
@@ -55,7 +55,7 @@ describe("Vanilla tests", () => {
55
55
assertRenderCount ( 3 ) ;
56
56
57
57
setSize ( { width : 321 , height : 456 } ) ;
58
- await delay ( 50 ) ;
58
+ await awaitNextFrame ( ) ;
59
59
assertSize ( { width : 321 , height : 456 } ) ;
60
60
assertRenderCount ( 4 ) ;
61
61
} ) ;
@@ -143,7 +143,7 @@ describe("Vanilla tests", () => {
143
143
handler . assertDefaultSize ( ) ;
144
144
145
145
// Actual measurement
146
- await delay ( 50 ) ;
146
+ await awaitNextFrame ( ) ;
147
147
handler . assertSize ( { width : 100 , height : 200 } ) ;
148
148
} ) ;
149
149
@@ -188,12 +188,12 @@ describe("Vanilla tests", () => {
188
188
handler . assertDefaultSize ( ) ;
189
189
190
190
// Div 1 measurement
191
- await delay ( 50 ) ;
191
+ await awaitNextFrame ( ) ;
192
192
handler . assertSize ( { width : 100 , height : 200 } ) ;
193
193
194
194
// Div 2 measurement
195
195
switchRefs ( ) ;
196
- await delay ( 50 ) ;
196
+ await awaitNextFrame ( ) ;
197
197
handler . assertSize ( { width : 150 , height : 250 } ) ;
198
198
} ) ;
199
199
@@ -204,7 +204,7 @@ describe("Vanilla tests", () => {
204
204
handler . assertDefaultSize ( ) ;
205
205
206
206
handler . setSize ( { width : 100 , height : 100 } ) ;
207
- await delay ( 50 ) ;
207
+ await awaitNextFrame ( ) ;
208
208
handler . assertSize ( { width : 100 , height : 100 } ) ;
209
209
} ) ;
210
210
@@ -214,18 +214,18 @@ describe("Vanilla tests", () => {
214
214
handler . assertDefaultSize ( ) ;
215
215
216
216
// Default render + first measurement
217
- await delay ( 50 ) ;
217
+ await awaitNextFrame ( ) ;
218
218
handler . assertRenderCount ( 2 ) ;
219
219
220
220
handler . setSize ( { width : 100 , height : 102 } ) ;
221
- await delay ( 50 ) ;
221
+ await awaitNextFrame ( ) ;
222
222
handler . assertSize ( { width : 100 , height : 102 } ) ;
223
223
handler . assertRenderCount ( 3 ) ;
224
224
225
225
// Shouldn't trigger on subpixel values that are rounded to be the same as the
226
226
// previous size
227
227
handler . setSize ( { width : 100.4 , height : 102.4 } ) ;
228
- await delay ( 50 ) ;
228
+ await awaitNextFrame ( ) ;
229
229
handler . assertSize ( { width : 100 , height : 102 } ) ;
230
230
handler . assertRenderCount ( 3 ) ;
231
231
} ) ;
@@ -309,7 +309,7 @@ describe("Vanilla tests", () => {
309
309
310
310
// Since no refs were passed in with an element to be measured, the hook should
311
311
// stay on the defaults
312
- await delay ( 50 ) ;
312
+ await awaitNextFrame ( ) ;
313
313
handler . assertDefaultSize ( ) ;
314
314
} ) ;
315
315
@@ -322,9 +322,9 @@ describe("Vanilla tests", () => {
322
322
) ;
323
323
324
324
handler . setSize ( { width : 100 , height : 200 } ) ;
325
- await delay ( 50 ) ;
325
+ await awaitNextFrame ( ) ;
326
326
handler . setSize ( { width : 101 , height : 201 } ) ;
327
- await delay ( 50 ) ;
327
+ await awaitNextFrame ( ) ;
328
328
329
329
// Should stay at default as width/height is not passed to the hook response
330
330
// when an onResize callback is given
@@ -371,25 +371,25 @@ describe("Vanilla tests", () => {
371
371
372
372
// Establishing a default, which'll be measured when the resize handler is set.
373
373
setSize ( { width : 1 , height : 1 } ) ;
374
- await delay ( 50 ) ;
374
+ await awaitNextFrame ( ) ;
375
375
376
376
assertRenderCount ( 1 ) ;
377
377
378
378
changeOnResizeHandler ( ( size : ObservedSize ) => observations1 . push ( size ) ) ;
379
- await delay ( 50 ) ;
379
+ await awaitNextFrame ( ) ;
380
380
setSize ( { width : 1 , height : 2 } ) ;
381
- await delay ( 50 ) ;
381
+ await awaitNextFrame ( ) ;
382
382
setSize ( { width : 3 , height : 4 } ) ;
383
383
384
384
assertRenderCount ( 2 ) ;
385
385
386
- await delay ( 50 ) ;
386
+ await awaitNextFrame ( ) ;
387
387
changeOnResizeHandler ( ( size : ObservedSize ) => observations2 . push ( size ) ) ;
388
- await delay ( 50 ) ;
388
+ await awaitNextFrame ( ) ;
389
389
setSize ( { width : 5 , height : 6 } ) ;
390
- await delay ( 50 ) ;
390
+ await awaitNextFrame ( ) ;
391
391
setSize ( { width : 7 , height : 8 } ) ;
392
- await delay ( 50 ) ;
392
+ await awaitNextFrame ( ) ;
393
393
394
394
assertRenderCount ( 3 ) ;
395
395
0 commit comments