-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomassert.coffee
More file actions
22 lines (19 loc) · 798 Bytes
/
domassert.coffee
File metadata and controls
22 lines (19 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
assert = require 'assert'
select = require('xpath.js')
Dom = require('xmldom').DOMParser
assert.hasTag = (xml, xpath, message) ->
doc = new Dom().parseFromString(xml)
elements = select(doc, xpath)
if elements[0] is undefined
throw new Error message || "XPath '#{xpath}' was not found in the document."
assert.hasTagWithContent = (xml, xpath, expected, message) ->
doc = new Dom().parseFromString(xml)
elements = select(doc, xpath)
if elements[0] is undefined
throw new Error message || "XPath '#{xpath}' was not found in the document."
foundMatch = false
for element in elements
if expected is element.textContent
foundMatch = true
if not foundMatch
throw new Error message || "XPath '#{xpath}' with content '#{expected}' was not found in the document."