From: Aleksander Ɓukasz Date: Thu, 24 Oct 2013 08:38:28 +0000 (+0200) Subject: smartxml: setting text on text node X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/3b0a39df2e007f33b027b665f0f42604aecfc8b9?hp=2f3c62f37144eb3878382f9cc655848965faea02 smartxml: setting text on text node --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index b81b0f0..53eefed 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -209,6 +209,10 @@ $.extend(TextNode.prototype, DocumentNode.prototype, { return this.nativeNode.data; }, + setText: function(text) { + this.nativeNode.data = text; + }, + appendText: function(text) { this.nativeNode.data = this.nativeNode.data + text; }, diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 2ccfa6d..b33ef1f 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -158,6 +158,16 @@ describe('smartxml', function() { }); }); + describe('Basic TextNode properties', function() { + it('can have its text set', function() { + var node = elementNodeFromXML('
Alice
'), + textNode = node.contents()[0]; + + textNode.setText('Cat'); + expect(textNode.getText()).to.equal('Cat'); + }); + }); + describe('Manipulations', function() { it('appends element node to another element node', function() {