Skip to content

Commit

Permalink
Add a test for the unsafeXML directive.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Dec 16, 2024
1 parent 29a50af commit a0cb692
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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="juliet@example.com/chamber" xmlns="jabber:client"></presence>');
const stanza = Strophe.Builder.fromString(
'<presence from="juliet@example.com/chamber" xmlns="jabber:client"></presence>'
);
assert.equal(isEqualNode(stanza, $pres({ from: 'juliet@example.com/chamber' })), true);
});

Expand Down Expand Up @@ -1218,11 +1220,24 @@ test('escape the values passed in to them', (assert) => {
);
});

test('The unsafeXML directive', (assert) => {
const templateStanza = stx`
<presence from="juliet@example.com/chamber"
xmlns="jabber:client">
${Strophe.Stanza.unsafeXML(`<status>I'm busy!</status>`)}
</presence>`;

assert.equal(
isEqualNode(templateStanza, $pres({ from: 'juliet@example.com/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);
Expand Down

0 comments on commit a0cb692

Please sign in to comment.