[IMP] components: add test for template string in props

This commit is contained in:
Samuel Degueldre
2021-11-24 08:44:53 +01:00
committed by Géry Debongnie
parent 9e81d14d50
commit 7869a1f2c6
3 changed files with 43 additions and 2 deletions
+2 -2
View File
@@ -5,9 +5,9 @@ import { globalTemplates } from "./app/template_set";
// Global templates
// -----------------------------------------------------------------------------
export function xml(strings: TemplateStringsArray, ...args: any[]) {
export function xml(...args: Parameters<typeof String.raw>) {
const name = `__template__${xml.nextId++}`;
const value = String.raw(strings, ...args);
const value = String.raw(...args);
globalTemplates[name] = value;
return name;
}
@@ -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);
}
}"
`;
+17
View File
@@ -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: ['<Child propName="`1${someVal}3`"/>'] });
static components = { Child };
someVal = 2;
}
await mount(Parent, fixture);
});
});