Skip to content

Commit

Permalink
fix(element): ensure props.children is an array in createElement
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 8, 2024
1 parent c5e90b4 commit 83ab991
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/element/__snapshots__/create.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,40 @@ exports[`creates element [Function Component] 6`] = `
"type": [Function],
}
`;

exports[`creates element [Function Component] 7`] = `
{
"key": null,
"props": {
"children": [
[Function],
[Function],
],
},
"type": [Function],
}
`;

exports[`creates element [Function Component] 8`] = `
{
"key": null,
"props": {
"children": [
[Function],
],
},
"type": [Function],
}
`;

exports[`creates element [Function Component] 9`] = `
{
"key": null,
"props": {
"children": [
[Function],
],
},
"type": [Function],
}
`;
3 changes: 3 additions & 0 deletions src/element/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ it.each([
[Component, { style: { width: 100, height: 200 } }],
[Component, { style: { width: 100, height: 200 } }, null],
[Component, { style: { width: 100, height: 200 } }, Component],
[Component, {}, Component, Component],
[Component, { children: Component }],
[Component, { children: [Component] }],
])('creates element %p', (...args) => {
expect(
// eslint-disable-next-line prefer-spread
Expand Down
4 changes: 4 additions & 0 deletions src/element/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function createElement(
props.children = children;
}

if (props.children && !Array.isArray(props.children)) {
props.children = [props.children];
}

return {
type,
props,
Expand Down

0 comments on commit 83ab991

Please sign in to comment.