diff --git a/index.js b/index.js index 09f2787..ae78ad4 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/test/elements.js b/test/elements.js index 661d5e9..f11a87e 100644 --- a/test/elements.js +++ b/test/elements.js @@ -48,8 +48,8 @@ test('svg', function (t) { ` 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() }) @@ -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) { @@ -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) {