File tree 4 files changed +14
-12
lines changed
4 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,15 @@ afterEach(() => {
12
12
consoleErrorMock . mockRestore ( )
13
13
} )
14
14
15
+ // no react-dom/test-utils also means no isomorphic act since isomorphic act got released after test-utils act
15
16
jest . 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
+ } )
16
24
17
25
test ( 'act works even when there is no act from test utils' , ( ) => {
18
26
const callback = jest . fn ( )
Original file line number Diff line number Diff line change @@ -2,8 +2,9 @@ import * as React from 'react'
2
2
import ReactDOM from 'react-dom'
3
3
import * as testUtils from 'react-dom/test-utils'
4
4
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
7
8
8
9
// act is supported [email protected]
9
10
// so for versions that don't have act from test utils
@@ -14,7 +15,7 @@ function actPolyfill(cb) {
14
15
ReactDOM . render ( < div /> , document . createElement ( 'div' ) )
15
16
}
16
17
17
- const act = reactAct || actPolyfill
18
+ const act = isomorphicAct || domAct || actPolyfill
18
19
19
20
let youHaveBeenWarned = false
20
21
let isAsyncActSupported = null
@@ -50,7 +51,7 @@ function asyncAct(cb) {
50
51
}
51
52
let cbReturn , result
52
53
try {
53
- result = reactAct ( ( ) => {
54
+ result = domAct ( ( ) => {
54
55
cbReturn = cb ( )
55
56
return cbReturn
56
57
} )
Original file line number Diff line number Diff line change @@ -14,10 +14,7 @@ configureDTL({
14
14
eventWrapper : cb => {
15
15
let result
16
16
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 ( )
21
18
} )
22
19
return result
23
20
} ,
Original file line number Diff line number Diff line change 1
1
import '@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