From 5f50988d300af984f4f4c476ac14124caef47f68 Mon Sep 17 00:00:00 2001 From: Ricky Hanlon Date: Thu, 18 Jan 2024 17:46:58 -0500 Subject: [PATCH] Convert ReactError-test to createRoot --- .../__tests__/ReactError-test.internal.js | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/shared/__tests__/ReactError-test.internal.js b/packages/shared/__tests__/ReactError-test.internal.js index 9411616fa3c93..a23c369f6cc8f 100644 --- a/packages/shared/__tests__/ReactError-test.internal.js +++ b/packages/shared/__tests__/ReactError-test.internal.js @@ -9,7 +9,8 @@ 'use strict'; let React; -let ReactDOM; +let ReactDOMClient; +let act; describe('ReactError', () => { let globalErrorMock; @@ -27,7 +28,8 @@ describe('ReactError', () => { } jest.resetModules(); React = require('react'); - ReactDOM = require('react-dom'); + ReactDOMClient = require('react-dom/client'); + act = require('internal-test-utils').act; }); afterEach(() => { @@ -39,7 +41,9 @@ describe('ReactError', () => { // @gate build === "production" // @gate !source it('should error with minified error code', () => { - expect(() => ReactDOM.render('Hi', null)).toThrowError( + expect(() => { + ReactDOMClient.createRoot(null); + }).toThrowError( 'Minified React error #200; visit ' + 'https://reactjs.org/docs/error-decoder.html?invariant=200' + ' for the full message or use the non-minified dev environment' + @@ -47,12 +51,25 @@ describe('ReactError', () => { ); }); - it('should serialize arguments', () => { + // @gate build === "production" + // @gate !source + it('should serialize arguments', async () => { function Oops() { - return; + return {}; } Oops.displayName = '#wtf'; + const container = document.createElement('div'); - expect(() => ReactDOM.render(, container)).not.toThrowError(); + const root = ReactDOMClient.createRoot(container); + await expect(async () => { + await act(async () => { + root.render(); + }); + }).rejects.toThrow( + 'Minified React error #152; visit ' + + 'https://reactjs.org/docs/error-decoder.html?invariant=152&args[]=%23wtf' + + ' for the full message or use the non-minified dev environment' + + ' for full errors and additional helpful warnings.', + ); }); });