@samitouri / QOS-React / commits / 710d5137e2

Remove ReactTestUtils from ReactIdentity (#28332)

Sebastian Silbermann committed Feb 15, 2024 at 19:14 UTC 710d5137e27db578dfec723b2c006821a1a61973
1 file changed +32 -18
packages/react-dom/src/__tests__/ReactIdentity-test.js
+32 -18
@@ -11,7 +11,6 @@
11
12 let React;
13 let ReactDOMClient;
14 -let ReactTestUtils;
14 let act;
15
16 describe('ReactIdentity', () => {
@@ -19,7 +18,6 @@ describe('ReactIdentity', () => {
18 jest.resetModules();
19 React = require('react');
20 ReactDOMClient = require('react-dom/client');
22 - ReactTestUtils = require('react-dom/test-utils');
21 act = require('internal-test-utils').act;
22 });
23
@@ -127,7 +125,7 @@ describe('ReactIdentity', () => {
125 expect(window.YOUVEBEENH4X0RED).toBe(undefined);
126 });
127
130 - it('should let restructured components retain their uniqueness', () => {
128 + it('should let restructured components retain their uniqueness', async () => {
129 const instance0 = <span />;
130 const instance1 = <span />;
131 const instance2 = <span />;
@@ -155,12 +153,16 @@ describe('ReactIdentity', () => {
153 }
154 }
155
158 - expect(function () {
159 - ReactTestUtils.renderIntoDocument(<TestContainer />);
160 - }).not.toThrow();
156 + const container = document.createElement('div');
157 + const root = ReactDOMClient.createRoot(container);
158 + await expect(
159 + act(() => {
160 + root.render(<TestContainer />);
161 + }),
162 + ).resolves.not.toThrow();
163 });
164
163 - it('should let nested restructures retain their uniqueness', () => {
165 + it('should let nested restructures retain their uniqueness', async () => {
166 const instance0 = <span />;
167 const instance1 = <span />;
168 const instance2 = <span />;
@@ -190,12 +192,16 @@ describe('ReactIdentity', () => {
192 }
193 }
194
193 - expect(function () {
194 - ReactTestUtils.renderIntoDocument(<TestContainer />);
195 - }).not.toThrow();
195 + const container = document.createElement('div');
196 + const root = ReactDOMClient.createRoot(container);
197 + await expect(
198 + act(() => {
199 + root.render(<TestContainer />);
200 + }),
201 + ).resolves.not.toThrow();
202 });
203
198 - it('should let text nodes retain their uniqueness', () => {
204 + it('should let text nodes retain their uniqueness', async () => {
205 class TestComponent extends React.Component {
206 render() {
207 return (
@@ -218,9 +224,13 @@ describe('ReactIdentity', () => {
224 }
225 }
226
221 - expect(function () {
222 - ReactTestUtils.renderIntoDocument(<TestContainer />);
223 - }).not.toThrow();
227 + const container = document.createElement('div');
228 + const root = ReactDOMClient.createRoot(container);
229 + await expect(
230 + act(() => {
231 + root.render(<TestContainer />);
232 + }),
233 + ).resolves.not.toThrow();
234 });
235
236 it('should retain key during updates in composite components', async () => {
@@ -272,7 +282,7 @@ describe('ReactIdentity', () => {
282 expect(beforeB).toBe(afterB);
283 });
284
275 - it('should not allow implicit and explicit keys to collide', () => {
285 + it('should not allow implicit and explicit keys to collide', async () => {
286 const component = (
287 <div>
288 <span />
@@ -280,9 +290,13 @@ describe('ReactIdentity', () => {
290 </div>
291 );
292
283 - expect(function () {
284 - ReactTestUtils.renderIntoDocument(component);
285 - }).not.toThrow();
293 + const container = document.createElement('div');
294 + const root = ReactDOMClient.createRoot(container);
295 + await expect(
296 + act(() => {
297 + root.render(component);
298 + }),
299 + ).resolves.not.toThrow();
300 });
301
302 it('should throw if key is a Temporal-like object', async () => {