Skip to content

Commit

Permalink
strip empty text nodes (choojs#68)
Browse files Browse the repository at this point in the history
* strip empty text nodes

* fixup! fix tests

Tests were acounting for random text nodes, this fixes the tests
  • Loading branch information
yoshuawuyts authored May 2, 2017
1 parent 6709607 commit 253d352
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function belCreateElement (tag, props, children) {
}

if (typeof node === 'string') {
if (/^[\n\r\s]+$/.test(node)) continue
if (el.lastChild && el.lastChild.nodeName === '#text') {
el.lastChild.nodeValue += node
continue
Expand Down
8 changes: 4 additions & 4 deletions test/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ test('svg', function (t) {
<use xlink:href="#test" />
</svg>`
t.equal(result.tagName, 'svg', 'create svg tag')
t.equal(result.childNodes[1].tagName, 'rect', 'created child rect tag')
t.equal(result.childNodes[3].getAttribute('xlink:href'), '#test', 'created child use tag with xlink:href')
t.equal(result.childNodes[0].tagName, 'rect', 'created child rect tag')
t.equal(result.childNodes[1].getAttribute('xlink:href'), '#test', 'created child use tag with xlink:href')
t.end()
})

Expand All @@ -63,7 +63,7 @@ test('svg with namespace', function (t) {
}
t.doesNotThrow(create)
t.equal(result.tagName, 'svg', 'create svg tag')
t.equal(result.childNodes[1].tagName, 'rect', 'created child rect tag')
t.equal(result.childNodes[0].tagName, 'rect', 'created child rect tag')
})

test('svg with xmlns:svg', function (t) {
Expand All @@ -76,7 +76,7 @@ test('svg with xmlns:svg', function (t) {
}
t.doesNotThrow(create)
t.equal(result.tagName, 'svg', 'create svg tag')
t.equal(result.childNodes[1].tagName, 'rect', 'created child rect tag')
t.equal(result.childNodes[0].tagName, 'rect', 'created child rect tag')
})

test('comments', function (t) {
Expand Down

0 comments on commit 253d352

Please sign in to comment.