File tree Expand file tree Collapse file tree 4 files changed +14
-12
lines changed
Expand file tree Collapse file tree 4 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,15 @@ afterEach(() => {
1212 consoleErrorMock . mockRestore ( )
1313} )
1414
15+ // no react-dom/test-utils also means no isomorphic act since isomorphic act got released after test-utils act
1516jest . mock ( 'react-dom/test-utils' , ( ) => ( { } ) )
17+ jest . mock ( 'react' , ( ) => {
18+ const ReactActual = jest . requireActual ( 'react' )
19+
20+ delete ReactActual . unstable_act
21+
22+ return ReactActual
23+ } )
1624
1725test ( 'act works even when there is no act from test utils' , ( ) => {
1826 const callback = jest . fn ( )
Original file line number Diff line number Diff line change @@ -2,8 +2,9 @@ import * as React from 'react'
22import ReactDOM from 'react-dom'
33import * as testUtils from 'react-dom/test-utils'
44
5- const reactAct = testUtils . act
6- const actSupported = reactAct !== undefined
5+ const isomorphicAct = React . unstable_act
6+ const domAct = testUtils . act
7+ const actSupported = domAct !== undefined
78
89// act is supported [email protected] 910// so for versions that don't have act from test utils
@@ -14,7 +15,7 @@ function actPolyfill(cb) {
1415 ReactDOM . render ( < div /> , document . createElement ( 'div' ) )
1516}
1617
17- const act = reactAct || actPolyfill
18+ const act = isomorphicAct || domAct || actPolyfill
1819
1920let youHaveBeenWarned = false
2021let isAsyncActSupported = null
@@ -50,7 +51,7 @@ function asyncAct(cb) {
5051 }
5152 let cbReturn , result
5253 try {
53- result = reactAct ( ( ) => {
54+ result = domAct ( ( ) => {
5455 cbReturn = cb ( )
5556 return cbReturn
5657 } )
Original file line number Diff line number Diff line change @@ -14,10 +14,7 @@ configureDTL({
1414 eventWrapper : cb => {
1515 let result
1616 act ( ( ) => {
17- // TODO: Remove ReactDOM.flushSync once `act` flushes the microtask queue.
18- // Otherwise `act` wrapping updates that schedule microtask would need to be followed with `await null` to flush the microtask queue manually
19- // See https://github.com/reactwg/react-18/discussions/21#discussioncomment-796755
20- result = ReactDOM . flushSync ( cb )
17+ result = cb ( )
2118 } )
2219 return result
2320 } ,
Original file line number Diff line number Diff line change 11import '@testing-library/jest-dom/extend-expect'
2-
3- // TODO: Can be removed in a future React release: https://github.com/reactwg/react-18/discussions/23#discussioncomment-798952
4- // eslint-disable-next-line import/no-extraneous-dependencies -- need the version from React not an explicitly declared one
5- jest . mock ( 'scheduler' , ( ) => require ( 'scheduler/unstable_mock' ) )
You can’t perform that action at this time.
0 commit comments