Skip to content

Commit 5d80b95

Browse files
jackpopeJack Pope
authored andcommitted
Use createRoot in ReactMockedComponent-test (#28087)
Co-authored-by: Jack Pope <jackpope@meta.com>
1 parent 16631c0 commit 5d80b95

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

+17-7
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)