From a0cb6920794b2929c8614d002da6d2ee6614cd25 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 16 Dec 2024 09:02:50 +0200 Subject: [PATCH] Add a test for the unsafeXML directive. --- tests/tests.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/tests.js b/tests/tests.js index 8135bff..f8283e1 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -150,7 +150,9 @@ test('Strophe.Connection.prototype.send() accepts Builders (#27)', (assert) => { }); test('The fromString static method', (assert) => { - const stanza = Strophe.Builder.fromString(''); + const stanza = Strophe.Builder.fromString( + '' + ); assert.equal(isEqualNode(stanza, $pres({ from: 'juliet@example.com/chamber' })), true); }); @@ -1218,11 +1220,24 @@ test('escape the values passed in to them', (assert) => { ); }); +test('The unsafeXML directive', (assert) => { + const templateStanza = stx` + + ${Strophe.Stanza.unsafeXML(`I'm busy!`)} + `; + + 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);