Skip to content

Commit

Permalink
spread props with children prop on components
Browse files Browse the repository at this point in the history
  • Loading branch information
David Mark Clements committed May 9, 2019
1 parent 458ca77 commit 181b7b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -465,7 +465,13 @@ function renderComponent (item, values) {
for (var sp in values[ix]) {
if (meta.spread[ix].after.indexOf(sp) > -1) continue
if (values[ix].hasOwnProperty(sp)) {
props[sp] = values[ix][sp]
if (sp === 'children') {
Object.defineProperty(props, 'children', {
value: values[ix][sp]
})
} else {
props[sp] = values[ix][sp]
}
}
}
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/ssr.test.js
Expand Up @@ -1850,6 +1850,18 @@ test('spread props and defaultProps', async ({ is }) => {
is(esx.renderToString`<Component/>`, renderToString(esx`<Component/>`))
})

test('spread props with children prop', async ({ is }) => {
const esx = init()
const Component = ({children}) => {
return esx`<p>${children}</p>`
}
esx.register({ Component })
const o = {children: 'test'}
const o2 = {children: 'test2'}
is(esx.renderToString`<Component ...${o}/>`, renderToString(esx`<Component ...${o}/>`))
is(esx.renderToString`<Component ...${o} ...${o2}/>`, renderToString(esx`<Component ...${o} ...${o2}/>`))
})

test('self closing void elements do not render with closing tag', async ({ is }) => {
const esx = init()
is(esx.renderToString`<area/>`, renderToString(esx`<area/>`))
Expand Down

0 comments on commit 181b7b7

Please sign in to comment.