Skip to content

Commit 9e13800

Browse files
authored
Remove ReactTestUtils from ReactArt-test (facebook#28059)
1 parent b2d6371 commit 9e13800

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

packages/react-art/src/__tests__/ReactART-test.js

+35-21
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import Wedge from 'react-art/Wedge';
2525
// Isolate DOM renderer.
2626
jest.resetModules();
2727
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;
2930

3031
// Isolate test renderer.
3132
jest.resetModules();
@@ -42,6 +43,7 @@ let Surface;
4243
let TestComponent;
4344

4445
let waitFor;
46+
let groupRef;
4547

4648
const Missing = {};
4749

@@ -82,8 +84,9 @@ describe('ReactART', () => {
8284

8385
({waitFor} = require('internal-test-utils'));
8486

87+
groupRef = React.createRef();
8588
TestComponent = class extends React.Component {
86-
group = React.createRef();
89+
group = groupRef;
8790

8891
render() {
8992
const a = (
@@ -132,17 +135,23 @@ describe('ReactART', () => {
132135
container = null;
133136
});
134137

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;
139145
// Duck type test for an ART group
140146
expect(typeof group.indicate).toBe('function');
141147
});
142148

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+
});
146155

147156
const expectedStructure = {
148157
nodeName: 'svg',
@@ -165,7 +174,7 @@ describe('ReactART', () => {
165174
],
166175
};
167176

168-
const realNode = ReactDOM.findDOMNode(instance);
177+
const realNode = container.firstChild;
169178
testDOMNodeStructure(realNode, expectedStructure);
170179
});
171180

@@ -243,7 +252,7 @@ describe('ReactART', () => {
243252
ReactDOM.unmountComponentAtNode(container);
244253
});
245254

246-
it('renders composite with lifecycle inside group', () => {
255+
it('renders composite with lifecycle inside group', async () => {
247256
let mounted = false;
248257

249258
class CustomShape extends React.Component {
@@ -255,18 +264,20 @@ describe('ReactART', () => {
255264
mounted = true;
256265
}
257266
}
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+
});
266277
expect(mounted).toBe(true);
267278
});
268279

269-
it('resolves refs before componentDidMount', () => {
280+
it('resolves refs before componentDidMount', async () => {
270281
class CustomShape extends React.Component {
271282
render() {
272283
return <Shape />;
@@ -293,7 +304,10 @@ describe('ReactART', () => {
293304
}
294305
}
295306

296-
ReactTestUtils.renderIntoDocument(<Outer />);
307+
const root = ReactDOMClient.createRoot(container);
308+
await act(() => {
309+
root.render(<Outer />);
310+
});
297311
expect(ref.constructor).toBe(CustomShape);
298312
});
299313

0 commit comments

Comments
 (0)