[IMP] component: improve error message when invalid handler

This commit is contained in:
Géry Debongnie
2022-01-20 14:52:47 +01:00
committed by Aaron Bohy
parent 3fb65b3a89
commit b33471e819
3 changed files with 41 additions and 1 deletions
+22
View File
@@ -33,6 +33,28 @@ describe("event handling", () => {
expect(fixture.innerHTML).toBe("<span><div>simple vnode</div>2</span>");
});
test("Invalid handler throws an error", async () => {
window.addEventListener(
"error",
(ev) => {
logStep(ev.error.message);
ev.preventDefault();
},
{ once: true }
);
class Parent extends Component {
static template = xml`<button t-on-click="dosomething">click</button>`;
doSomething() {}
}
await mount(Parent, fixture);
expect([]).toBeLogged();
fixture.querySelector("button")!.click();
expect(["Invalid handler (expected a function, received: 'undefined')"]).toBeLogged();
});
test("support for callable expression in event handler", async () => {
class Counter extends Component {
static template = xml`