Skip to content

Commit 49267d4

Browse files
committed
Add test case for flattened children lists
1 parent 6b46ad9 commit 49267d4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/react/src/__tests__/ReactChildren-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,26 @@ describe('ReactChildren', () => {
868868
]);
869869
});
870870

871+
it('should warn for flattened children lists', async () => {
872+
function ComponentRenderingFlattenedChildren({children}) {
873+
return <div>{React.Children.toArray(children)}</div>;
874+
}
875+
876+
const container = document.createElement('div');
877+
const root = ReactDOMClient.createRoot(container);
878+
await expect(async () => {
879+
await act(() => {
880+
root.render(
881+
<ComponentRenderingFlattenedChildren>
882+
{[<div />]}
883+
</ComponentRenderingFlattenedChildren>,
884+
);
885+
});
886+
}).toErrorDev([
887+
'Warning: Each child in a list should have a unique "key" prop.',
888+
]);
889+
});
890+
871891
it('does not warn for flattened positional children', async () => {
872892
function ComponentRenderingFlattenedChildren({children}) {
873893
return <div>{React.Children.toArray(children)}</div>;

0 commit comments

Comments
 (0)