diff --git a/src/vhtml.js b/src/vhtml.js index 0e03f69..48e975f 100644 --- a/src/vhtml.js +++ b/src/vhtml.js @@ -42,7 +42,7 @@ export default function h(name, attrs) { } else while (stack.length) { let child = stack.pop(); - if (child) { + if (child !== undefined && child !== null) { if (child.pop) { for (let i=child.length; i--; ) stack.push(child[i]); } diff --git a/test/vhtml.js b/test/vhtml.js index f88ddf2..7b3501d 100644 --- a/test/vhtml.js +++ b/test/vhtml.js @@ -174,7 +174,34 @@ describe('vhtml', () => { ); }); - it('should support string fragments', () => { + it('should render a child of 0', () => { + function Child ({ children }) { + return {children}; + } + expect( +
{0}
+ ).to.equal( + '
0
' + ); + }); + + it('should not attempt to render a child of null or undefined', () => { + function Child ({ children }) { + return {children}; + } + expect( +
{null}
+ ).to.equal( + '
' + ); + expect( +
{undefined}
+ ).to.equal( + '
' + ); + }); + + it('should support string fragments', () => { expect( h(null, null, "foo", "bar", "baz") ).to.equal( @@ -189,5 +216,4 @@ describe('vhtml', () => { '

foo

bar
baz
' ); }); - });