@samitouri / QOS-React-2 / commits / 7db2446c3d

Convert ReactJSXElementValidator to createRoot (#28209)

Ricky committed Feb 2, 2024 at 12:56 UTC 7db2446c3d10ddd22746f5a1cf8173156f23654e
1 file changed +12 -3
packages/react/src/__tests__/ReactJSXElementValidator-test.js
+12 -3
@@ -13,8 +13,10 @@
13 // of dynamic errors when using JSX with Flow.
14 let React;
15 let ReactDOM;
16 +let ReactDOMClient;
17 let ReactTestUtils;
18 let PropTypes;
19 +let act;
20
21 describe('ReactJSXElementValidator', () => {
22 let Component;
@@ -26,7 +28,9 @@ describe('ReactJSXElementValidator', () => {
28 PropTypes = require('prop-types');
29 React = require('react');
30 ReactDOM = require('react-dom');
31 + ReactDOMClient = require('react-dom/client');
32 ReactTestUtils = require('react-dom/test-utils');
33 + act = require('internal-test-utils').act;
34
35 Component = class extends React.Component {
36 render() {
@@ -172,7 +176,7 @@ describe('ReactJSXElementValidator', () => {
176 );
177 });
178
175 - it('should update component stack after receiving next element', () => {
179 + it('should update component stack after receiving next element', async () => {
180 function MyComp() {
181 return null;
182 }
@@ -192,9 +196,14 @@ describe('ReactJSXElementValidator', () => {
196 }
197
198 const container = document.createElement('div');
195 - ReactDOM.render(<ParentComp warn={false} />, container);
199 + const root = ReactDOMClient.createRoot(container);
200 + await act(() => {
201 + root.render(<ParentComp warn={false} />);
202 + });
203 expect(() =>
197 - ReactDOM.render(<ParentComp warn={true} />, container),
204 + ReactDOM.flushSync(() => {
205 + root.render(<ParentComp warn={true} />);
206 + }),
207 ).toErrorDev(
208 'Warning: Failed prop type: ' +
209 'Invalid prop `color` of type `number` supplied to `MyComp`, ' +