File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -139,18 +139,14 @@ describe.each([
139139 test ( 'waitForElementToBeRemoved' , async ( ) => {
140140 await render ( < ComponentWithMicrotaskLoader /> )
141141 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 / )
143144 expect ( screen . getByTestId ( 'message' ) ) . toHaveTextContent ( / H e l l o W o r l d / )
144145 } )
145146
146- test ( 'waitFor' , async ( ) => {
147+ test ( 'waitFor is not needed since microtasks are flushed ' , async ( ) => {
147148 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+
154150 expect ( screen . getByTestId ( 'message' ) ) . toHaveTextContent ( / H e l l o W o r l d / )
155151 } )
156152
Original file line number Diff line number Diff line change @@ -28,6 +28,12 @@ function jestFakeTimersAreEnabled() {
2828
2929configureDTL ( {
3030 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.
3137 return act ( cb )
3238 } ,
3339 // We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
You can’t perform that action at this time.
0 commit comments