From 29fbf6f62625c4262035f931681c7b7822ca9843 Mon Sep 17 00:00:00 2001 From: Ricky Date: Fri, 19 Jan 2024 14:35:56 -0500 Subject: [PATCH] Convert ReactError-test to createRoot (#27995) --- .../__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 ba25cfdab3e6b..e881c71b4de60 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://react.dev/errors/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.', + ); }); });