« get me outta code hell

infra, test: new stubTemplate utility (slots permissable & as-are) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-02 12:34:39 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-02 12:34:39 -0300
commitb4018984c7d3a9b6fd94721ab5df1b4b7124bc0a (patch)
treebb19f5952b7001c26db74ac74d89e86c997908ed
parenta88b415391b1c191292a9a0aa7e40152066483e2 (diff)
infra, test: new stubTemplate utility (slots permissable & as-are)
-rw-r--r--test/lib/content-function.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/lib/content-function.js b/test/lib/content-function.js
index 5216c4f..a9e5f44 100644
--- a/test/lib/content-function.js
+++ b/test/lib/content-function.js
@@ -90,6 +90,29 @@ export function testContentFunctions(t, message, fn) {
       t.matchSnapshot(result, description);
     };
 
+    evaluate.stubTemplate = name => {
+      // Creates a particularly permissable template, allowing any slot values
+      // to be stored and just outputting the contents of those slots as-are.
+
+      return new (class extends html.Template {
+        #slotValues = {};
+
+        constructor() {
+          super({
+            content: () => `${name}: ${JSON.stringify(this.#slotValues)}`,
+          });
+        }
+
+        setSlots(slotNamesToValues) {
+          Object.assign(this.#slotValues, slotNamesToValues);
+        }
+
+        setSlot(slotName, slotValue) {
+          this.#slotValues[slotName] = slotValue;
+        }
+      });
+    };
+
     evaluate.mock = (...opts) => {
       const {value, close} = mock(...opts);
       mocks.push({close});