From 11ee4548da5e5e4297d020356c6d1014475d6b05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 20 Nov 2013 13:31:45 +0100 Subject: [PATCH] smartxml: fix - handle creation of an empty text node --- src/smartxml/smartxml.js | 2 +- src/smartxml/smartxml.test.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 6f3d7de..0a1a354 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -372,7 +372,7 @@ $.extend(Document.prototype, Backbone.Events, { createDocumentNode: function(from) { if(!(from instanceof Node)) { - if(from.text) { + if(from.text !== undefined) { from = document.createTextNode(from.text); } else { var node = $('<' + from.tagName + '>'); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index ccaf0ef..a0c1af4 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -51,6 +51,14 @@ describe('smartxml', function() { expect(doc.containsNode(a)).to.equal(true, 'contains Element Node'); expect(doc.containsNode(text)).to.equal(true, 'contains Text Node'); }); + + it('creates text nodes', function() { + var doc = getDocumentFromXML('
'), + emptyTextNode = doc.createDocumentNode({text:''}), + nonEmptyTextNode = doc.createDocumentNode({text: 'alice'}); + expect(emptyTextNode.getText()).to.equal('', 'empty ok'); + expect(nonEmptyTextNode.getText()).to.equal('alice', 'non empty ok'); + }); }); describe('Basic ElementNode properties', function() { -- 2.20.1