fix(test-renderer): indent on multiple children

This commit is contained in:
Evan You 2018-10-01 17:50:02 -04:00
parent 4f6531aa3c
commit 3fe047b4ac
2 changed files with 11 additions and 5 deletions

View File

@ -132,16 +132,21 @@ describe('test renderer', () => {
{
id: 'test'
},
'hello'
[h('span', 'foo'), 'hello']
)
}
}
const root = nodeOps.createElement('div')
render(h(App), root)
expect(serialize(root)).toEqual(`<div><div id="test">hello</div></div>`)
expect(serialize(root)).toEqual(
`<div><div id="test"><span>foo</span>hello</div></div>`
)
expect(serialize(root, 2)).toEqual(
`<div>
<div id="test">
<span>
foo
</span>
hello
</div>
</div>`

View File

@ -22,10 +22,11 @@ function serializeElement(
return `${key}=${JSON.stringify(node.props[key])}`
})
.join(' ')
const newLine = indent ? `\n` : ``
const children = node.children.length
? (indent ? `\n` : ``) +
node.children.map(c => serialize(c, indent, depth + 1)) +
(indent ? `\n` : ``)
? newLine +
node.children.map(c => serialize(c, indent, depth + 1)).join(newLine) +
newLine
: ``
const padding = indent ? ` `.repeat(indent).repeat(depth) : ``
return (