Skip to content

Commit

Permalink
Add test case for flattened children lists
Browse files Browse the repository at this point in the history
  • Loading branch information
yungsters committed May 30, 2024
1 parent 6b46ad9 commit 49267d4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/react/src/__tests__/ReactChildren-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,26 @@ describe('ReactChildren', () => {
]);
});

it('should warn for flattened children lists', async () => {
function ComponentRenderingFlattenedChildren({children}) {
return <div>{React.Children.toArray(children)}</div>;
}

const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(async () => {
await act(() => {
root.render(
<ComponentRenderingFlattenedChildren>
{[<div />]}
</ComponentRenderingFlattenedChildren>,
);
});
}).toErrorDev([
'Warning: Each child in a list should have a unique "key" prop.',
]);
});

it('does not warn for flattened positional children', async () => {
function ComponentRenderingFlattenedChildren({children}) {
return <div>{React.Children.toArray(children)}</div>;
Expand Down

0 comments on commit 49267d4

Please sign in to comment.