Skip to content

Commit 54f2314

Browse files
jackpopeJack Pope
and
Jack Pope
authored
Use createRoot in ReactMockedComponent-test (#28087)
Co-authored-by: Jack Pope <[email protected]>
1 parent 4c41c09 commit 54f2314

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/react-dom/src/__tests__/ReactMockedComponent-test.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
'use strict';
1111

1212
let React;
13-
let ReactDOM;
13+
let ReactDOMClient;
14+
let act;
1415

1516
let MockedComponent;
1617
let ReactDOMServer;
1718

1819
describe('ReactMockedComponent', () => {
1920
beforeEach(() => {
2021
React = require('react');
21-
ReactDOM = require('react-dom');
22+
ReactDOMClient = require('react-dom/client');
2223
ReactDOMServer = require('react-dom/server');
24+
act = require('internal-test-utils').act;
2325

2426
MockedComponent = class extends React.Component {
2527
render() {
@@ -30,15 +32,23 @@ describe('ReactMockedComponent', () => {
3032
MockedComponent.prototype.render = jest.fn();
3133
});
3234

33-
it('should allow a mocked component to be rendered', () => {
35+
it('should allow a mocked component to be rendered', async () => {
3436
const container = document.createElement('container');
35-
ReactDOM.render(<MockedComponent />, container);
37+
const root = ReactDOMClient.createRoot(container);
38+
await act(() => {
39+
root.render(<MockedComponent />);
40+
});
3641
});
3742

38-
it('should allow a mocked component to be updated in dev', () => {
43+
it('should allow a mocked component to be updated in dev', async () => {
3944
const container = document.createElement('container');
40-
ReactDOM.render(<MockedComponent />, container);
41-
ReactDOM.render(<MockedComponent />, container);
45+
const root = ReactDOMClient.createRoot(container);
46+
await act(() => {
47+
root.render(<MockedComponent />);
48+
});
49+
await act(() => {
50+
root.render(<MockedComponent />);
51+
});
4252
});
4353

4454
it('should allow a mocked component to be rendered in dev (SSR)', () => {

0 commit comments

Comments
 (0)