diff --git a/packages/react-dom/src/__tests__/ReactDOMSelection-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMSelection-test.internal.js index 251e98d67533d..9457137ff4f5a 100644 --- a/packages/react-dom/src/__tests__/ReactDOMSelection-test.internal.js +++ b/packages/react-dom/src/__tests__/ReactDOMSelection-test.internal.js @@ -10,16 +10,18 @@ 'use strict'; let React; -let ReactDOM; +let ReactDOMClient; let ReactDOMSelection; +let act; let getModernOffsetsFromPoints; describe('ReactDOMSelection', () => { beforeEach(() => { React = require('react'); - ReactDOM = require('react-dom'); + ReactDOMClient = require('react-dom/client'); ReactDOMSelection = require('react-dom-bindings/src/client/ReactDOMSelection'); + act = require('internal-test-utils').act; ({getModernOffsetsFromPoints} = ReactDOMSelection); }); @@ -74,53 +76,57 @@ describe('ReactDOMSelection', () => { // Complicated example derived from a real-world DOM tree. Has a bit of // everything. - function getFixture() { - return ReactDOM.render( -
+ async function getFixture() { + const container = document.createElement('div'); + const root = ReactDOMClient.createRoot(container); + await act(() => { + root.render(
-
-
xxxxxxxxxxxxxxxxxxxx
-
- x
- x +
xxxxxxxxxxxxxxxxxxxx
+
+ x +
+ x
-
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-
-
-
xxxxxxxxxxxxxxxxxx
+
+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+
+
+
xxxxxxxxxxxxxxxxxx
+
+
-
-
-
-
xxxx
-
xxxxxxxxxxxxxxxxxxx
+
+
xxxx
+
xxxxxxxxxxxxxxxxxxx
+
-
-
xxx
-
xxxxx
-
xxx
-
+
xxx
+
xxxxx
+
xxx
-
{['x', 'x', 'xxx']}
+
+
{['x', 'x', 'xxx']}
+
-
-
-
xxxxxx
-
-
, - document.createElement('div'), - ); +
+
xxxxxx
+
+
, + ); + }); + return container.firstChild; } it('returns correctly for base case', () => { @@ -135,8 +141,8 @@ describe('ReactDOMSelection', () => { }); }); - it('returns correctly for fuzz test', () => { - const fixtureRoot = getFixture(); + it('returns correctly for fuzz test', async () => { + const fixtureRoot = await getFixture(); const allNodes = [fixtureRoot].concat( Array.from(fixtureRoot.querySelectorAll('*')), );