Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ReactError-test to createRoot #27995

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://reactjs.org/docs/error-decoder.html?invariant=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.',
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverts this back to what it was before #21869

In that PR, we allow returning undefined from render. The test was updated (stupidly, by me) to just pass. But the test is to confirm arguments are serialized correctly, so the right fix is to change it to an error that includes arguments.

I've chosen rendering an object as the error.

});
});