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'
|
id: 'test'
|
||||||
},
|
},
|
||||||
'hello'
|
[h('span', 'foo'), 'hello']
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const root = nodeOps.createElement('div')
|
const root = nodeOps.createElement('div')
|
||||||
render(h(App), root)
|
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(
|
expect(serialize(root, 2)).toEqual(
|
||||||
`<div>
|
`<div>
|
||||||
<div id="test">
|
<div id="test">
|
||||||
|
<span>
|
||||||
|
foo
|
||||||
|
</span>
|
||||||
hello
|
hello
|
||||||
</div>
|
</div>
|
||||||
</div>`
|
</div>`
|
||||||
|
@ -22,10 +22,11 @@ function serializeElement(
|
|||||||
return `${key}=${JSON.stringify(node.props[key])}`
|
return `${key}=${JSON.stringify(node.props[key])}`
|
||||||
})
|
})
|
||||||
.join(' ')
|
.join(' ')
|
||||||
|
const newLine = indent ? `\n` : ``
|
||||||
const children = node.children.length
|
const children = node.children.length
|
||||||
? (indent ? `\n` : ``) +
|
? newLine +
|
||||||
node.children.map(c => serialize(c, indent, depth + 1)) +
|
node.children.map(c => serialize(c, indent, depth + 1)).join(newLine) +
|
||||||
(indent ? `\n` : ``)
|
newLine
|
||||||
: ``
|
: ``
|
||||||
const padding = indent ? ` `.repeat(indent).repeat(depth) : ``
|
const padding = indent ? ` `.repeat(indent).repeat(depth) : ``
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user