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

Fix ReactJSXElementValidator tests #29192

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 15 additions & 6 deletions packages/react/src/__tests__/ReactJSXElementValidator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('ReactJSXElementValidator', () => {

Component = class extends React.Component {
render() {
return <div />;
return <div>{this.props.children}</div>;
}
};

Expand Down Expand Up @@ -97,7 +97,11 @@ describe('ReactJSXElementValidator', () => {
await act(() => {
root.render(<Component>{iterable}</Component>);
});
}).toErrorDev('Each child in a list should have a unique "key" prop.');
}).toErrorDev([
'Each child in a list should have a unique "key" prop.',
'Each child in a list should have a unique "key" prop.',
'Each child in a list should have a unique "key" prop.',
]);
});

it('does not warn for arrays of elements with keys', async () => {
Expand Down Expand Up @@ -137,7 +141,7 @@ describe('ReactJSXElementValidator', () => {
});
});

it('does not warn for numeric keys in entry iterable as a child', async () => {
it('warns when using map-like iterables as a child', async () => {
const iterable = {
'@@iterator': function () {
let i = 0;
Expand All @@ -153,9 +157,14 @@ describe('ReactJSXElementValidator', () => {

const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<Component>{iterable}</Component>);
});
await expect(async () => {
await act(() => {
root.render(<Component>{iterable}</Component>);
});
}).toErrorDev([
'Using Maps as children is not supported. Use an array of keyed ReactElements instead.',
'Each child in a list should have a unique "key" prop.',
]);
});

it('does not warn when the element is directly as children', async () => {
Expand Down