[IMP] components: crash when using unknown suffix/modifiers

This commit is contained in:
Géry Debongnie
2022-01-19 11:35:34 +01:00
committed by aab-odoo
parent f7843c7c00
commit b06791c950
4 changed files with 35 additions and 5 deletions
+8
View File
@@ -480,6 +480,14 @@ describe("t-on", () => {
button.click();
});
test("t-on crashes when used with unknown modifier", async () => {
const template = `<div t-on-click.somemodifier="onClick" />`;
let owner = { onClick(e: Event) {} };
expect(() => mountToFixture(template, owner)).toThrowError("Unknown event modifier");
});
test("t-on combined with t-esc", async () => {
expect.assertions(3);
const template = `<div><button t-on-click="onClick" t-esc="text"/></div>`;
@@ -122,7 +122,7 @@ exports[`basics support prop names that aren't valid bare object property names
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return component(\`Child\`, {'some-dashed-prop': 5,'a.b': 'keyword prop'}, key + \`__1\`, node, ctx);
return component(\`Child\`, {'some-dashed-prop': 5}, key + \`__1\`, node, ctx);
}
}"
`;
+17 -3
View File
@@ -142,17 +142,16 @@ describe("basics", () => {
});
test("support prop names that aren't valid bare object property names", async () => {
expect.assertions(4);
expect.assertions(3);
class Child extends Component {
static template = xml`<button t-on-click="props.onClick"/>`;
setup() {
expect(this.props["some-dashed-prop"]).toBe(5);
expect(this.props["a.b"]).toBe("keyword prop");
}
}
class Parent extends Component {
static template = xml`<Child some-dashed-prop="5" a.b="'keyword prop'"/>`;
static template = xml`<Child some-dashed-prop="5"/>`;
static components = { Child };
}
await mount(Parent, fixture);
@@ -225,3 +224,18 @@ test("bound functions is referentially equal after update", async () => {
expect(fixture.innerHTML).toBe("3");
expect(isEqual).toBe(true);
});
test("throw if prop uses an unknown suffix", async () => {
class Child extends Component {
static template = xml`<t t-esc="props.val"/>`;
}
class Parent extends Component {
static template = xml`<Child val.somesuffix="state.val"/>`;
static components = { Child };
}
await expect(async () => {
await mount(Parent, fixture);
}).rejects.toThrowError("Invalid prop suffix");
});