From 2943ca39219110ce0764fc88b2f1cd01e622001c Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Wed, 24 Nov 2021 08:44:53 +0100 Subject: [PATCH] [IMP] components: add test for template string in props --- src/tags.ts | 4 ++-- .../__snapshots__/props.test.ts.snap | 24 +++++++++++++++++++ tests/components/props.test.ts | 17 +++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/tags.ts b/src/tags.ts index d5ff02cd..42af326e 100644 --- a/src/tags.ts +++ b/src/tags.ts @@ -5,9 +5,9 @@ import { globalTemplates } from "./app/template_set"; // Global templates // ----------------------------------------------------------------------------- -export function xml(strings: TemplateStringsArray, ...args: any[]) { +export function xml(...args: Parameters) { const name = `__template__${xml.nextId++}`; - const value = String.raw(strings, ...args); + const value = String.raw(...args); globalTemplates[name] = value; return name; } diff --git a/tests/components/__snapshots__/props.test.ts.snap b/tests/components/__snapshots__/props.test.ts.snap index 235debe3..c6356885 100644 --- a/tests/components/__snapshots__/props.test.ts.snap +++ b/tests/components/__snapshots__/props.test.ts.snap @@ -251,3 +251,27 @@ exports[`basics t-set works 2`] = ` } }" `; + +exports[`basics template string in prop 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers; + + return function template(ctx, node, key = \\"\\") { + return text(\`\`); + } +}" +`; + +exports[`basics template string in prop 2`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers; + + return function template(ctx, node, key = \\"\\") { + return component(\`Child\`, {propName: \`1\${ctx['someVal']}3\`}, key + \`__1\`, node, ctx); + } +}" +`; diff --git a/tests/components/props.test.ts b/tests/components/props.test.ts index 29a092c9..a9706f79 100644 --- a/tests/components/props.test.ts +++ b/tests/components/props.test.ts @@ -158,4 +158,21 @@ describe("basics", () => { } await mount(Parent, fixture); }); + + test("template string in prop", async () => { + expect.assertions(3); + class Child extends Component { + static template = xml``; + setup() { + expect(this.props.propName).toBe("123"); + } + } + + class Parent extends Component { + static template = xml({ raw: [''] }); + static components = { Child }; + someVal = 2; + } + await mount(Parent, fixture); + }); });