« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-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 5216c4f2..a9e5f449 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});