[IMP] t-on directive: allow empty handler

Closes #377
This commit is contained in:
Aaron Bohy
2019-10-25 10:58:18 +02:00
committed by Géry Debongnie
parent 0ea1091692
commit 2beb12678e
7 changed files with 131 additions and 14 deletions
@@ -1789,6 +1789,22 @@ exports[`t-on t-on combined with t-raw 1`] = `
}"
`;
exports[`t-on t-on with empty handler (only modifiers) 1`] = `
"function anonymous(context,extra
) {
let owner = context;
var h = this.h;
let c1 = [], p1 = {key:1};
var vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2,on:{}};
var vn2 = h('button', p2, c2);
c1.push(vn2);
p2.on['click'] = function (e) {e.preventDefault();};
c2.push({text: \`Button\`});
return vn1;
}"
`;
exports[`t-on t-on with inline statement (function call) 1`] = `
"function anonymous(context,extra
) {
+18
View File
@@ -1213,6 +1213,24 @@ describe("t-on", () => {
expect(steps).toEqual([1, 2]);
});
test("t-on with empty handler (only modifiers)", () => {
expect.assertions(2);
qweb.addTemplate(
"test",
`<div>
<button t-on-click.prevent="">Button</button>
</div>`
);
const node = renderToDOM(qweb, "test", {}, { handlers: [] });
node.addEventListener('click', (e) => {
expect(e.defaultPrevented).toBe(true);
});
const button = (<HTMLElement>node).getElementsByTagName("button")[0];
button.click();
});
test("t-on combined with t-esc", async () => {
expect.assertions(3);
qweb.addTemplate("test", `<div><button t-on-click="onClick" t-esc="text"/></div>`);