Skip to content

Commit

Permalink
Convert ReactChildren to createRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Silbermann committed Feb 1, 2024
1 parent d29f7d9 commit 32247d9
Showing 1 changed file with 26 additions and 12 deletions.
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

0 comments on commit 32247d9

Please sign in to comment.