Skip to content

Commit

Permalink
fix: export new act when available (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanBobi authored May 1, 2024
1 parent f6a1677 commit b6e59f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,27 @@
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.6",
"@types/react": "^18.3.1",
"chalk": "^4.1.2",
"dotenv-cli": "^4.0.0",
"jest-diff": "^29.7.0",
"kcd-scripts": "^13.0.0",
"npm-run-all": "^4.1.5",
"react": "^18.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.0",
"rimraf": "^3.0.2",
"typescript": "^4.1.2"
},
"peerDependencies": {
"@types/react": "^18.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
},
"eslintConfig": {
"extends": "./node_modules/kcd-scripts/eslint.js",
"parserOptions": {
Expand Down
12 changes: 7 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
prettyFormat,
Config as ConfigDTL,
} from '@testing-library/dom'
import {act as reactAct} from 'react-dom/test-utils'
import {act as reactDeprecatedAct} from 'react-dom/test-utils'
//@ts-ignore
import {act as reactAct} from 'react'

export * from '@testing-library/dom'

Expand Down Expand Up @@ -245,10 +247,10 @@ export function renderHook<
export function cleanup(): void

/**
* Simply calls ReactDOMTestUtils.act(cb)
* Simply calls React.act(cb)
* If that's not available (older version of react) then it
* simply calls the given callback immediately
* simply calls the deprecated version which is ReactTestUtils.act(cb)
*/
export const act: typeof reactAct extends undefined
? (callback: () => void) => void
export const act: typeof reactAct extends never
? typeof reactDeprecatedAct
: typeof reactAct

0 comments on commit b6e59f7

Please sign in to comment.