Remove ReactTestUtils from ReactArt-test (#28059)
Jack Pope committed
Jan 23, 2024 at 17:05 UTC
9e13800e5731435a1e8ff4bd0266e7cd4adc8d4f
1 file changed
+35
-21
packages/react-art/src/__tests__/ReactART-test.js
+35
-21
@@ -25,7 +25,8 @@ import Wedge from 'react-art/Wedge';
25
// Isolate DOM renderer.
26
jest.resetModules();
27
const ReactDOM = require('react-dom');
28
-const ReactTestUtils = require('react-dom/test-utils');
28
+const ReactDOMClient = require('react-dom/client');
29
+const act = require('internal-test-utils').act;
30
31
// Isolate test renderer.
32
jest.resetModules();
@@ -42,6 +43,7 @@ let Surface;
43
let TestComponent;
44
45
let waitFor;
46
+let groupRef;
47
48
const Missing = {};
49
@@ -82,8 +84,9 @@ describe('ReactART', () => {
84
85
({waitFor} = require('internal-test-utils'));
86
87
+ groupRef = React.createRef();
88
TestComponent = class extends React.Component {
86
- group = React.createRef();
89
+ group = groupRef;
90
91
render() {
92
const a = (
@@ -132,17 +135,23 @@ describe('ReactART', () => {
135
container = null;
136
});
137
135
- it('should have the correct lifecycle state', () => {
136
- let instance = <TestComponent />;
137
- instance = ReactTestUtils.renderIntoDocument(instance);
138
- const group = instance.group.current;
138
+ it('should have the correct lifecycle state', async () => {
139
+ const instance = <TestComponent />;
140
+ const root = ReactDOMClient.createRoot(container);
141
+ await act(() => {
142
+ root.render(instance);
143
+ });
144
+ const group = groupRef.current;
145
// Duck type test for an ART group
146
expect(typeof group.indicate).toBe('function');
147
});
148
143
- it('should render a reasonable SVG structure in SVG mode', () => {
144
- let instance = <TestComponent />;
145
- instance = ReactTestUtils.renderIntoDocument(instance);
149
+ it('should render a reasonable SVG structure in SVG mode', async () => {
150
+ const instance = <TestComponent />;
151
+ const root = ReactDOMClient.createRoot(container);
152
+ await act(() => {
153
+ root.render(instance);
154
+ });
155
156
const expectedStructure = {
157
nodeName: 'svg',
@@ -165,7 +174,7 @@ describe('ReactART', () => {
174
],
175
};
176
168
- const realNode = ReactDOM.findDOMNode(instance);
177
+ const realNode = container.firstChild;
178
testDOMNodeStructure(realNode, expectedStructure);
179
});
180
@@ -243,7 +252,7 @@ describe('ReactART', () => {
252
ReactDOM.unmountComponentAtNode(container);
253
});
254
246
- it('renders composite with lifecycle inside group', () => {
255
+ it('renders composite with lifecycle inside group', async () => {
256
let mounted = false;
257
258
class CustomShape extends React.Component {
@@ -255,18 +264,20 @@ describe('ReactART', () => {
264
mounted = true;
265
}
266
}
258
-
259
- ReactTestUtils.renderIntoDocument(
260
- <Surface>
261
- <Group>
262
- <CustomShape />
263
- </Group>
264
- </Surface>,
265
- );
267
+ const root = ReactDOMClient.createRoot(container);
268
+ await act(() => {
269
+ root.render(
270
+ <Surface>
271
+ <Group>
272
+ <CustomShape />
273
+ </Group>
274
+ </Surface>,
275
+ );
276
+ });
277
expect(mounted).toBe(true);
278
});
279
269
- it('resolves refs before componentDidMount', () => {
280
+ it('resolves refs before componentDidMount', async () => {
281
class CustomShape extends React.Component {
282
render() {
283
return <Shape />;
@@ -293,7 +304,10 @@ describe('ReactART', () => {
304
}
305
}
306
296
- ReactTestUtils.renderIntoDocument(<Outer />);
307
+ const root = ReactDOMClient.createRoot(container);
308
+ await act(() => {
309
+ root.render(<Outer />);
310
+ });
311
expect(ref.constructor).toBe(CustomShape);
312
});
313