mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component: improve error message when invalid handler
This commit is contained in:
committed by
Aaron Bohy
parent
3fb65b3a89
commit
b33471e819
@@ -1,5 +1,19 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`event handling Invalid handler throws an error 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<button block-handler-0=\\"click\\">click</button>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let hdlr1 = [ctx['dosomething'], ctx];
|
||||
return block1([hdlr1]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`event handling handler is not called if component is destroyed 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user