Skip to content

Commit

Permalink
Convert ReactError-test to createRoot (#27995)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii authored Jan 19, 2024
1 parent 4c63dc7 commit 29fbf6f
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions packages/shared/__tests__/ReactError-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
'use strict';

let React;
let ReactDOM;
let ReactDOMClient;
let act;

describe('ReactError', () => {
let globalErrorMock;
Expand All @@ -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(() => {
Expand All @@ -39,20 +41,35 @@ 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' +
' for full errors and additional helpful warnings.',
);
});

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(<Oops />, container)).not.toThrowError();
const root = ReactDOMClient.createRoot(container);
await expect(async () => {
await act(async () => {
root.render(<Oops />);
});
}).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.',
);
});
});

0 comments on commit 29fbf6f

Please sign in to comment.