From 52e20fdc10e5a56cedb1802379e0e1f5ba9cd8f0 Mon Sep 17 00:00:00 2001 From: jerrydev0927 Date: Sun, 17 Dec 2023 13:17:45 +0000 Subject: [PATCH] fix[devtools/e2e]: add fallback for act in integration tests (#27842) https://github.com/facebook/react/pull/27805 broke integration tests for React DevTools with React 17, these changes introduce a fallback for such case when `act` is not available in `react`, but available in `react-dom`, like before. --- packages/react-devtools-shared/src/__tests__/utils.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-devtools-shared/src/__tests__/utils.js b/packages/react-devtools-shared/src/__tests__/utils.js index bf5a8b98ea..1a74c1fee9 100644 --- a/packages/react-devtools-shared/src/__tests__/utils.js +++ b/packages/react-devtools-shared/src/__tests__/utils.js @@ -19,7 +19,9 @@ export function act( recursivelyFlush: boolean = true, ): void { const {act: actTestRenderer} = require('react-test-renderer'); - const actDOM = require('react').unstable_act; + // Use `require('react-dom/test-utils').act` as a fallback for React 17, which can be used in integration tests for React DevTools. + const actDOM = + require('react').unstable_act || require('react-dom/test-utils').act; actDOM(() => { actTestRenderer(() => { @@ -44,7 +46,9 @@ export async function actAsync( recursivelyFlush: boolean = true, ): Promise { const {act: actTestRenderer} = require('react-test-renderer'); - const actDOM = require('react').unstable_act; + // Use `require('react-dom/test-utils').act` as a fallback for React 17, which can be used in integration tests for React DevTools. + const actDOM = + require('react').unstable_act || require('react-dom/test-utils').act; await actDOM(async () => { await actTestRenderer(async () => {