-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomassert.js
More file actions
36 lines (30 loc) · 1.1 KB
/
domassert.js
File metadata and controls
36 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(function() {
var Dom, assert, select;
assert = require('assert');
select = require('xpath.js');
Dom = require('xmldom').DOMParser;
assert.hasTag = function(xml, xpath, message) {
var doc, elements;
doc = new Dom().parseFromString(xml);
elements = select(doc, xpath);
if (elements[0] === void 0) {
throw new Error(message || ("XPath '" + xpath + "' was not found in the document."));
}
};
assert.hasTagWithContent = function(xml, xpath, expected, message) {
var doc, element, elements, foundMatch, _i, _len;
doc = new Dom().parseFromString(xml);
elements = select(doc, xpath);
if (elements[0] === void 0) {
throw new Error(message || ("XPath '" + xpath + "' was not found in the document."));
}
foundMatch = false;
for (_i = 0, _len = elements.length; _i < _len; _i++) {
element = elements[_i];
if (expected === element.textContent) foundMatch = true;
}
if (!foundMatch) {
throw new Error(message || ("XPath '" + xpath + "' with content '" + expected + "' was not found in the document."));
}
};
}).call(this);