From b6e59f7d58c69f617cc9854d8c3e6f86c2dfb0e9 Mon Sep 17 00:00:00 2001 From: Matan Borenkraout Date: Wed, 1 May 2024 21:29:24 +0300 Subject: [PATCH] fix: export new act when available (#1319) --- package.json | 9 ++++++++- types/index.d.ts | 12 +++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 3c38a74e..0b7876a8 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/types/index.d.ts b/types/index.d.ts index 099bbe84..c1cb345f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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' @@ -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