From 9cae4428a13c1377df9b4a752f8d87646df461ec Mon Sep 17 00:00:00 2001 From: Josh Story Date: Wed, 6 Dec 2023 12:57:14 -0800 Subject: [PATCH] Update act references in tests (#27805) As part of the process of removing the deprecated `react-dom/test-utils` package references to `act` from this module are replaced with references to `unstable_act` in `react`. It is likely that the unstable act implementation will be made stable. The test utils act is just a reexport of the unstable_act implementation in react itself. --- fixtures/dom/src/__tests__/nested-act-test.js | 4 ++-- packages/react-devtools-shared/src/__tests__/utils.js | 4 ++-- .../react-dom/src/__tests__/ReactDOMHydrationDiff-test.js | 2 +- .../src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js | 2 +- packages/react-refresh/src/__tests__/ReactFresh-test.js | 4 ++-- .../react-refresh/src/__tests__/ReactFreshIntegration-test.js | 2 +- .../src/__tests__/ReactFlightDOMForm-test.js | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fixtures/dom/src/__tests__/nested-act-test.js b/fixtures/dom/src/__tests__/nested-act-test.js index d57bef7310e41..4a4c63eaad105 100644 --- a/fixtures/dom/src/__tests__/nested-act-test.js +++ b/fixtures/dom/src/__tests__/nested-act-test.js @@ -20,7 +20,7 @@ describe('unmocked scheduler', () => { beforeEach(() => { jest.resetModules(); React = require('react'); - DOMAct = require('react-dom/test-utils').act; + DOMAct = React.unstable_act; TestRenderer = require('react-test-renderer'); TestAct = TestRenderer.act; }); @@ -61,7 +61,7 @@ describe('mocked scheduler', () => { require.requireActual('scheduler/unstable_mock') ); React = require('react'); - DOMAct = require('react-dom/test-utils').act; + DOMAct = React.unstable_act; TestRenderer = require('react-test-renderer'); TestAct = TestRenderer.act; }); diff --git a/packages/react-devtools-shared/src/__tests__/utils.js b/packages/react-devtools-shared/src/__tests__/utils.js index 0c5a0b09f7d01..bf5a8b98eab23 100644 --- a/packages/react-devtools-shared/src/__tests__/utils.js +++ b/packages/react-devtools-shared/src/__tests__/utils.js @@ -19,7 +19,7 @@ export function act( recursivelyFlush: boolean = true, ): void { const {act: actTestRenderer} = require('react-test-renderer'); - const {act: actDOM} = require('react-dom/test-utils'); + const actDOM = require('react').unstable_act; actDOM(() => { actTestRenderer(() => { @@ -44,7 +44,7 @@ export async function actAsync( recursivelyFlush: boolean = true, ): Promise { const {act: actTestRenderer} = require('react-test-renderer'); - const {act: actDOM} = require('react-dom/test-utils'); + const actDOM = require('react').unstable_act; await actDOM(async () => { await actTestRenderer(async () => { diff --git a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js index 3bdcd9c16a966..45de6fa9104f4 100644 --- a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js @@ -25,7 +25,7 @@ describe('ReactDOMServerHydration', () => { React = require('react'); ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; console.error = jest.fn(); container = document.createElement('div'); diff --git a/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js b/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js index e0bce1c01ca69..a38d4c0698ced 100644 --- a/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js +++ b/packages/react-dom/src/__tests__/ReactTestUtilsActUnmockedScheduler-test.js @@ -37,7 +37,7 @@ beforeEach(() => { yields = []; React = require('react'); ReactDOM = require('react-dom'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; container = document.createElement('div'); document.body.appendChild(container); }); diff --git a/packages/react-refresh/src/__tests__/ReactFresh-test.js b/packages/react-refresh/src/__tests__/ReactFresh-test.js index aa7b2504227e0..8ce009ed72043 100644 --- a/packages/react-refresh/src/__tests__/ReactFresh-test.js +++ b/packages/react-refresh/src/__tests__/ReactFresh-test.js @@ -34,7 +34,7 @@ describe('ReactFresh', () => { ReactDOM = require('react-dom'); ReactDOMClient = require('react-dom/client'); Scheduler = require('scheduler'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; internalAct = require('internal-test-utils').act; const InternalTestUtils = require('internal-test-utils'); @@ -3792,7 +3792,7 @@ describe('ReactFresh', () => { React = require('react'); ReactDOM = require('react-dom'); Scheduler = require('scheduler'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; internalAct = require('internal-test-utils').act; // Important! Inject into the global hook *after* ReactDOM runs: diff --git a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js index 54e596f6232c3..ee7a9230bb14e 100644 --- a/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js +++ b/packages/react-refresh/src/__tests__/ReactFreshIntegration-test.js @@ -31,7 +31,7 @@ describe('ReactFreshIntegration', () => { ReactFreshRuntime = require('react-refresh/runtime'); ReactFreshRuntime.injectIntoGlobalHook(global); ReactDOM = require('react-dom'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; container = document.createElement('div'); document.body.appendChild(container); exportsObj = undefined; diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js index d21c456b8e087..89b436907f201 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js @@ -54,7 +54,7 @@ describe('ReactFlightDOMForm', () => { ReactServerDOMClient = require('react-server-dom-webpack/client.edge'); ReactDOMServer = require('react-dom/server.edge'); ReactDOMClient = require('react-dom/client'); - act = require('react-dom/test-utils').act; + act = React.unstable_act; useFormState = require('react-dom').useFormState; container = document.createElement('div'); document.body.appendChild(container);