fix(test-renderer): indent on multiple children
This commit is contained in:
parent
4f6531aa3c
commit
3fe047b4ac
@ -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>`
|
||||
|
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user