fix(runtime-test): output empty attrs without value in seralized output

This commit is contained in:
Evan You 2019-12-17 11:50:10 -05:00
parent 31ca7858bb
commit 3d16c0ea5a
2 changed files with 9 additions and 4 deletions

View File

@ -126,7 +126,8 @@ describe('test renderer', () => {
return h( return h(
'div', 'div',
{ {
id: 'test' id: 'test',
boolean: ''
}, },
[h('span', 'foo'), 'hello'] [h('span', 'foo'), 'hello']
) )
@ -135,12 +136,12 @@ describe('test renderer', () => {
const root = nodeOps.createElement('div') const root = nodeOps.createElement('div')
render(h(App), root) render(h(App), root)
expect(serialize(root)).toEqual( expect(serialize(root)).toEqual(
`<div><div id="test"><span>foo</span>hello</div></div>` `<div><div id="test" boolean><span>foo</span>hello</div></div>`
) )
// indented output // indented output
expect(serialize(root, 2)).toEqual( expect(serialize(root, 2)).toEqual(
`<div> `<div>
<div id="test"> <div id="test" boolean>
<span> <span>
foo foo
</span> </span>

View File

@ -40,7 +40,11 @@ function serializeElement(
const props = Object.keys(node.props) const props = Object.keys(node.props)
.map(key => { .map(key => {
const value = node.props[key] const value = node.props[key]
return isOn(key) || value == null ? `` : `${key}=${JSON.stringify(value)}` return isOn(key) || value == null
? ``
: value === ``
? key
: `${key}=${JSON.stringify(value)}`
}) })
.filter(Boolean) .filter(Boolean)
.join(' ') .join(' ')