From b4018984c7d3a9b6fd94721ab5df1b4b7124bc0a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 2 Aug 2023 12:34:39 -0300 Subject: infra, test: new stubTemplate utility (slots permissable & as-are) --- test/lib/content-function.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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}); -- cgit 1.3.0-6-gf8a5