Skip to content

Commit b6e59f7

Browse files
authoredMay 1, 2024
fix: export new act when available (#1319)
1 parent f6a1677 commit b6e59f7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed
 

‎package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,27 @@
5151
},
5252
"devDependencies": {
5353
"@testing-library/jest-dom": "^5.11.6",
54+
"@types/react": "^18.3.1",
5455
"chalk": "^4.1.2",
5556
"dotenv-cli": "^4.0.0",
5657
"jest-diff": "^29.7.0",
5758
"kcd-scripts": "^13.0.0",
5859
"npm-run-all": "^4.1.5",
59-
"react": "^18.3.0",
60+
"react": "^18.3.1",
6061
"react-dom": "^18.3.0",
6162
"rimraf": "^3.0.2",
6263
"typescript": "^4.1.2"
6364
},
6465
"peerDependencies": {
66+
"@types/react": "^18.0.0",
6567
"react": "^18.0.0",
6668
"react-dom": "^18.0.0"
6769
},
70+
"peerDependenciesMeta": {
71+
"@types/react": {
72+
"optional": true
73+
}
74+
},
6875
"eslintConfig": {
6976
"extends": "./node_modules/kcd-scripts/eslint.js",
7077
"parserOptions": {

‎types/index.d.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
prettyFormat,
88
Config as ConfigDTL,
99
} from '@testing-library/dom'
10-
import {act as reactAct} from 'react-dom/test-utils'
10+
import {act as reactDeprecatedAct} from 'react-dom/test-utils'
11+
//@ts-ignore
12+
import {act as reactAct} from 'react'
1113

1214
export * from '@testing-library/dom'
1315

@@ -245,10 +247,10 @@ export function renderHook<
245247
export function cleanup(): void
246248

247249
/**
248-
* Simply calls ReactDOMTestUtils.act(cb)
250+
* Simply calls React.act(cb)
249251
* If that's not available (older version of react) then it
250-
* simply calls the given callback immediately
252+
* simply calls the deprecated version which is ReactTestUtils.act(cb)
251253
*/
252-
export const act: typeof reactAct extends undefined
253-
? (callback: () => void) => void
254+
export const act: typeof reactAct extends never
255+
? typeof reactDeprecatedAct
254256
: typeof reactAct

0 commit comments

Comments
 (0)
Failed to load comments.