mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] blockdom: toString method in multi could crash
This commit is contained in:
committed by
Aaron Bohy
parent
281b32965e
commit
7711733a23
@@ -127,7 +127,7 @@ export class VMulti {
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.children.map((c) => c!.toString()).join("");
|
||||
return this.children.map((c) => (c ? c!.toString() : "")).join("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,11 @@ describe("multi blocks", () => {
|
||||
expect(fixture.innerHTML).toBe("ab");
|
||||
});
|
||||
|
||||
test("multi vnode can be used as text", () => {
|
||||
mount(text(multi([text("a"), undefined]) as any), fixture);
|
||||
expect(fixture.innerHTML).toBe("a");
|
||||
});
|
||||
|
||||
test("multi inside a block", async () => {
|
||||
const block = createBlock("<div><block-child-0/></div>");
|
||||
const tree = block([], [multi([text("foo"), text("bar")])]);
|
||||
|
||||
@@ -87,6 +87,31 @@ exports[`t-set set from attribute lookup 1`] = `
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`t-set set from body literal (with t-if/t-else 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
let { isBoundary, withDefault, LazyValue } = helpers;
|
||||
|
||||
function value1(ctx, node, key = \\"\\") {
|
||||
let b2,b3;
|
||||
if (ctx['condition']) {
|
||||
b2 = text(\`true\`);
|
||||
} else {
|
||||
b3 = text(\`false\`);
|
||||
}
|
||||
return multi([b2, b3]);
|
||||
}
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
ctx = Object.create(ctx);
|
||||
ctx[isBoundary] = 1
|
||||
ctx[\`value\`] = new LazyValue(value1, ctx, node);
|
||||
return text(ctx['value']);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`t-set set from body literal 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -38,6 +38,19 @@ describe("t-set", () => {
|
||||
expect(renderToString(template)).toBe("ok");
|
||||
});
|
||||
|
||||
test("set from body literal (with t-if/t-else", () => {
|
||||
const template = `
|
||||
<t>
|
||||
<t t-set="value">
|
||||
<t t-if="condition">true</t>
|
||||
<t t-else="">false</t>
|
||||
</t>
|
||||
<t t-esc="value"/>
|
||||
</t>`;
|
||||
expect(renderToString(template, { condition: true })).toBe("true");
|
||||
expect(renderToString(template, { condition: false })).toBe("false");
|
||||
});
|
||||
|
||||
test("set from attribute lookup", () => {
|
||||
const template = `<div><t t-set="stuff" t-value="value"/><t t-esc="stuff"/></div>`;
|
||||
expect(renderToString(template, { value: "ok" })).toBe("<div>ok</div>");
|
||||
|
||||
Reference in New Issue
Block a user