-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for the unsafeXML directive.
- Loading branch information
Showing
1 changed file
with
17 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,7 +150,9 @@ test('Strophe.Connection.prototype.send() accepts Builders (#27)', (assert) => { | |
}); | ||
|
||
test('The fromString static method', (assert) => { | ||
const stanza = Strophe.Builder.fromString('<presence from="[email protected]/chamber" xmlns="jabber:client"></presence>'); | ||
const stanza = Strophe.Builder.fromString( | ||
'<presence from="[email protected]/chamber" xmlns="jabber:client"></presence>' | ||
); | ||
assert.equal(isEqualNode(stanza, $pres({ from: '[email protected]/chamber' })), true); | ||
}); | ||
|
||
|
@@ -1218,11 +1220,24 @@ test('escape the values passed in to them', (assert) => { | |
); | ||
}); | ||
|
||
test('The unsafeXML directive', (assert) => { | ||
const templateStanza = stx` | ||
<presence from="[email protected]/chamber" | ||
xmlns="jabber:client"> | ||
${Strophe.Stanza.unsafeXML(`<status>I'm busy!</status>`)} | ||
</presence>`; | ||
|
||
assert.equal( | ||
isEqualNode(templateStanza, $pres({ from: '[email protected]/chamber' }).c('status').t("I'm busy!")), | ||
true | ||
); | ||
}); | ||
|
||
const TEXT_NODE = 3; | ||
const ELEMENT_NODE = 1; | ||
|
||
function stripEmptyTextNodes(element) { | ||
const childNodes = Array.from(element.childNodes ?? []); | ||
const childNodes = Array.from(element.childNodes ?? []); | ||
childNodes.forEach((node) => { | ||
if (node.nodeType === TEXT_NODE && !node.nodeValue.trim()) { | ||
element.removeChild(node); | ||
|