@@ -292,12 +292,11 @@ test('the real timers => fake timers error shows the original stack trace when c
292
292
293
293
test ( 'does not work after it resolves' , async ( ) => {
294
294
jest . useFakeTimers ( 'modern' )
295
- let context = 'initial'
295
+ const contextStack = [ ]
296
296
configure ( {
297
297
// @testing -library/react usage to ensure `IS_REACT_ACT_ENVIRONMENT` is set when acting.
298
298
unstable_advanceTimersWrapper : callback => {
299
- const originalContext = context
300
- context = 'act'
299
+ contextStack . push ( 'act:start' )
301
300
try {
302
301
const result = callback ( )
303
302
// eslint-disable-next-line jest/no-if, jest/no-conditional-in-test -- false-positive
@@ -307,32 +306,31 @@ test('does not work after it resolves', async () => {
307
306
then : ( resolve , reject ) => {
308
307
thenable . then (
309
308
returnValue => {
310
- context = originalContext
309
+ contextStack . push ( 'act:end' )
311
310
resolve ( returnValue )
312
311
} ,
313
312
error => {
314
- context = originalContext
313
+ contextStack . push ( 'act:end' )
315
314
reject ( error )
316
315
} ,
317
316
)
318
317
} ,
319
318
}
320
319
} else {
321
- context = originalContext
320
+ contextStack . push ( 'act:end' )
322
321
return undefined
323
322
}
324
323
} catch {
325
- context = originalContext
324
+ contextStack . push ( 'act:end' )
326
325
return undefined
327
326
}
328
327
} ,
329
328
asyncWrapper : async callback => {
330
- const originalContext = context
331
- context = 'no-act'
329
+ contextStack . push ( 'no-act:start' )
332
330
try {
333
331
await callback ( )
334
332
} finally {
335
- context = originalContext
333
+ contextStack . push ( 'no-act:end' )
336
334
}
337
335
} ,
338
336
} )
@@ -342,6 +340,7 @@ test('does not work after it resolves', async () => {
342
340
data = 'resolved'
343
341
} , 100 )
344
342
343
+ contextStack . push ( 'waitFor:start' )
345
344
await waitFor (
346
345
( ) => {
347
346
// eslint-disable-next-line jest/no-conditional-in-test -- false-positive
@@ -351,10 +350,29 @@ test('does not work after it resolves', async () => {
351
350
} ,
352
351
{ interval : 50 } ,
353
352
)
354
-
355
- expect ( context ) . toEqual ( 'initial' )
353
+ contextStack . push ( 'waitFor:end' )
354
+
355
+ expect ( contextStack ) . toEqual ( [
356
+ 'waitFor:start' ,
357
+ 'no-act:start' ,
358
+ 'act:start' ,
359
+ 'act:end' ,
360
+ 'act:start' ,
361
+ 'act:end' ,
362
+ 'no-act:end' ,
363
+ 'waitFor:end' ,
364
+ ] )
356
365
357
366
await Promise . resolve ( )
358
367
359
- expect ( context ) . toEqual ( 'initial' )
368
+ expect ( contextStack ) . toEqual ( [
369
+ 'waitFor:start' ,
370
+ 'no-act:start' ,
371
+ 'act:start' ,
372
+ 'act:end' ,
373
+ 'act:start' ,
374
+ 'act:end' ,
375
+ 'no-act:end' ,
376
+ 'waitFor:end' ,
377
+ ] )
360
378
} )
0 commit comments