|
9 | 9 | 'use strict'; |
10 | 10 |
|
11 | 11 | let React; |
12 | | -let ReactDOM; |
| 12 | +let ReactDOMClient; |
| 13 | +let act; |
13 | 14 |
|
14 | 15 | describe('ReactError', () => { |
15 | 16 | let globalErrorMock; |
@@ -27,7 +28,8 @@ describe('ReactError', () => { |
27 | 28 | } |
28 | 29 | jest.resetModules(); |
29 | 30 | React = require('react'); |
30 | | - ReactDOM = require('react-dom'); |
| 31 | + ReactDOMClient = require('react-dom/client'); |
| 32 | + act = require('internal-test-utils').act; |
31 | 33 | }); |
32 | 34 |
|
33 | 35 | afterEach(() => { |
@@ -39,20 +41,35 @@ describe('ReactError', () => { |
39 | 41 | // @gate build === "production" |
40 | 42 | // @gate !source |
41 | 43 | it('should error with minified error code', () => { |
42 | | - expect(() => ReactDOM.render('Hi', null)).toThrowError( |
| 44 | + expect(() => { |
| 45 | + ReactDOMClient.createRoot(null); |
| 46 | + }).toThrowError( |
43 | 47 | 'Minified React error #200; visit ' + |
44 | 48 | 'https://react.dev/errors/200' + |
45 | 49 | ' for the full message or use the non-minified dev environment' + |
46 | 50 | ' for full errors and additional helpful warnings.', |
47 | 51 | ); |
48 | 52 | }); |
49 | 53 |
|
50 | | - it('should serialize arguments', () => { |
| 54 | + // @gate build === "production" |
| 55 | + // @gate !source |
| 56 | + it('should serialize arguments', async () => { |
51 | 57 | function Oops() { |
52 | | - return; |
| 58 | + return {}; |
53 | 59 | } |
54 | 60 | Oops.displayName = '#wtf'; |
| 61 | + |
55 | 62 | const container = document.createElement('div'); |
56 | | - expect(() => ReactDOM.render(<Oops />, container)).not.toThrowError(); |
| 63 | + const root = ReactDOMClient.createRoot(container); |
| 64 | + await expect(async () => { |
| 65 | + await act(async () => { |
| 66 | + root.render(<Oops />); |
| 67 | + }); |
| 68 | + }).rejects.toThrow( |
| 69 | + 'Minified React error #152; visit ' + |
| 70 | + 'https://reactjs.org/docs/error-decoder.html?invariant=152&args[]=%23wtf' + |
| 71 | + ' for the full message or use the non-minified dev environment' + |
| 72 | + ' for full errors and additional helpful warnings.', |
| 73 | + ); |
57 | 74 | }); |
58 | 75 | }); |