File tree 2 files changed +10
-8
lines changed
2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -139,18 +139,14 @@ describe.each([
139
139
test ( 'waitForElementToBeRemoved' , async ( ) => {
140
140
await render ( < ComponentWithMicrotaskLoader /> )
141
141
const loading = ( ) => screen . getByText ( 'Loading..' )
142
- await waitForElementToBeRemoved ( loading )
142
+ // Already flushed microtasks so we'll never see the loading state in a test.
143
+ expect ( loading ) . toThrowError ( / U n a b l e t o f i n d a n e l e m e n t w i t h t h e t e x t / )
143
144
expect ( screen . getByTestId ( 'message' ) ) . toHaveTextContent ( / H e l l o W o r l d / )
144
145
} )
145
146
146
- test ( 'waitFor' , async ( ) => {
147
+ test ( 'waitFor is not needed since microtasks are flushed ' , async ( ) => {
147
148
await render ( < ComponentWithMicrotaskLoader /> )
148
- await waitFor ( ( ) => {
149
- screen . getByText ( 'Loading..' )
150
- } )
151
- await waitFor ( ( ) => {
152
- screen . getByText ( / L o a d e d t h i s m e s s a g e : / )
153
- } )
149
+
154
150
expect ( screen . getByTestId ( 'message' ) ) . toHaveTextContent ( / H e l l o W o r l d / )
155
151
} )
156
152
Original file line number Diff line number Diff line change @@ -28,6 +28,12 @@ function jestFakeTimersAreEnabled() {
28
28
29
29
configureDTL ( {
30
30
unstable_advanceTimersWrapper : cb => {
31
+ // Only needed to support test environments that enable fake timers after modules are loaded.
32
+ // React's scheduler will detect fake timers when it's initialized and use them.
33
+ // So if we change the timers after that, we need to re-initialize the scheduler.
34
+ // But not every test runner supports module reset.
35
+ // It's not even clear how modules should be reset in ESM.
36
+ // So for this brief period we go back to using the act queue.
31
37
return act ( cb )
32
38
} ,
33
39
// We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
You can’t perform that action at this time.
0 commit comments