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 ReactChildren to createRoot #28191

Merged
merged 1 commit into from
Feb 2, 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
38 changes: 26 additions & 12 deletions packages/react/src/__tests__/ReactChildren-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

describe('ReactChildren', () => {
let React;
let ReactTestUtils;
let ReactDOMClient;
let act;

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactTestUtils = require('react-dom/test-utils');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;
});

it('should support identity for simple', () => {
Expand Down Expand Up @@ -962,37 +964,49 @@ describe('ReactChildren', () => {
});

describe('with fragments enabled', () => {
it('warns for keys for arrays of elements in a fragment', () => {
it('warns for keys for arrays of elements in a fragment', async () => {
class ComponentReturningArray extends React.Component {
render() {
return [<div />, <div />];
}
}

expect(() =>
ReactTestUtils.renderIntoDocument(<ComponentReturningArray />),
).toErrorDev(
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(async () => {
await act(() => {
root.render(<ComponentReturningArray />);
});
}).toErrorDev(
'Warning: ' +
'Each child in a list should have a unique "key" prop.' +
' See https://reactjs.org/link/warning-keys for more information.' +
'\n in ComponentReturningArray (at **)',
);
});

it('does not warn when there are keys on elements in a fragment', () => {
it('does not warn when there are keys on elements in a fragment', async () => {
class ComponentReturningArray extends React.Component {
render() {
return [<div key="foo" />, <div key="bar" />];
}
}

ReactTestUtils.renderIntoDocument(<ComponentReturningArray />);
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<ComponentReturningArray />);
});
});

it('warns for keys for arrays at the top level', () => {
expect(() =>
ReactTestUtils.renderIntoDocument([<div />, <div />]),
).toErrorDev(
it('warns for keys for arrays at the top level', async () => {
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(async () => {
await act(() => {
root.render([<div />, <div />]);
});
}).toErrorDev(
'Warning: ' +
'Each child in a list should have a unique "key" prop.' +
' See https://reactjs.org/link/warning-keys for more information.',
Expand Down