@samitouri / QOS-React / commits / 54f2314e9c

Use createRoot in ReactMockedComponent-test (#28087)

Co-authored-by: Jack Pope <jackpope@meta.com>

Jack Pope committed Jan 26, 2024 at 17:28 UTC 54f2314e9cfe82baf1c040a55ed4dfff6488f84e
1 file changed +17 -7
packages/react-dom/src/__tests__/ReactMockedComponent-test.js
+17 -7
@@ -10,7 +10,8 @@
10 'use strict';
11
12 let React;
13 -let ReactDOM;
13 +let ReactDOMClient;
14 +let act;
15
16 let MockedComponent;
17 let ReactDOMServer;
@@ -18,8 +19,9 @@ let ReactDOMServer;
19 describe('ReactMockedComponent', () => {
20 beforeEach(() => {
21 React = require('react');
21 - ReactDOM = require('react-dom');
22 + ReactDOMClient = require('react-dom/client');
23 ReactDOMServer = require('react-dom/server');
24 + act = require('internal-test-utils').act;
25
26 MockedComponent = class extends React.Component {
27 render() {
@@ -30,15 +32,23 @@ describe('ReactMockedComponent', () => {
32 MockedComponent.prototype.render = jest.fn();
33 });
34
33 - it('should allow a mocked component to be rendered', () => {
35 + it('should allow a mocked component to be rendered', async () => {
36 const container = document.createElement('container');
35 - ReactDOM.render(<MockedComponent />, container);
37 + const root = ReactDOMClient.createRoot(container);
38 + await act(() => {
39 + root.render(<MockedComponent />);
40 + });
41 });
42
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 () => {
44 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 + });
52 });
53
54 it('should allow a mocked component to be rendered in dev (SSR)', () => {