[Pkg-javascript-commits] [ltx] 249/469: Element.prototype.getChildText() selects elements just like .getChild()
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:03:08 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit f7977f53c6018c6a4ed5f380f0b402570d264a9c
Author: Astro <astro at spaceboyz.net>
Date: Tue Aug 14 00:19:53 2012 +0200
Element.prototype.getChildText() selects elements just like .getChild()
Fixes Github issue #15
---
lib/element.js | 12 +++---------
test/element-test.js | 18 ++++++++++++++++++
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/lib/element.js b/lib/element.js
index 02a786f..7189847 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -118,15 +118,9 @@ Element.prototype.getText = function() {
return text;
};
-Element.prototype.getChildText = function(name) {
- var text = null;
- for(var i = 0; i < this.children.length; i++) {
- var child = this.children[i];
- if (!text && child.name == name) {
- text = child.getText();
- }
- }
- return text;
+Element.prototype.getChildText = function(name, xmlns) {
+ var child = this.getChild(name, xmlns);
+ return child ? child.getText() : null;
};
/*** Builder ***/
diff --git a/test/element-test.js b/test/element-test.js
index 7ae5607..e3c94fa 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -148,5 +148,23 @@ vows.describe('ltx').addBatch({
.t('bar').root();
assert.equal(el.getChildByAttr('id', 'x', null, true).toString(), '<c id="x">bar</c>');
}
+ },
+
+ "issue #15: Inconsistency with prefixed elements": {
+ topic: function() {
+ return ltx.parse('<root><x:foo>bar</x:foo></root>');
+ },
+ "getChildText prefixed": function(el) {
+ assert.equal(el.getChildText('x:foo'), null);
+ },
+ "getChildText unprefixed": function(el) {
+ assert.equal(el.getChildText('foo'), 'bar');
+ },
+ "getChild prefixed": function(el) {
+ assert.equal(el.getChild('x:foo'), null);
+ },
+ "getChild unprefixed": function(el) {
+ assert.equal(el.getChild('foo').getText(), 'bar');
+ }
}
}).export(module);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list