Skip to content

Commit

Permalink
createElement: ignore null and undefined children (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp authored Jun 12, 2016
1 parent bb42870 commit 191d33d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/createElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = function createElement (name, attrs /*, child1, child2, ...*/)
var el = new Element(name, attrs)

for (var i = 2; i < arguments.length; i++) {
el.cnode(arguments[i])
var child = arguments[i]
if (child) el.cnode(child)
}

return el
Expand Down
8 changes: 8 additions & 0 deletions test/createElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@ vows.describe('createElement').addBatch({
assert.equal(e.children.length, 2)
assert.equal(e.children[0], 'foo')
assert.equal(e.children[1], c)
},
'null and undefined children are discarded': function () {
var e = createElement('foo', null, undefined, 'bar', null, createElement('test'), 'baz')
var b = new Element('foo')
.t('bar')
.c('test').up()
.t('baz')
assert.equal(e.root().toString(), b.root().toString())
}
}).export(module)

0 comments on commit 191d33d

Please sign in to comment.