[FIX] component: scoping issue with t-on and t-foreach

closes #193
This commit is contained in:
Géry Debongnie
2019-06-21 16:23:42 +02:00
parent e6a5934162
commit 63a8fcd7e2
3 changed files with 107 additions and 5 deletions
+28
View File
@@ -1888,6 +1888,34 @@ describe("random stuff/miscellaneous", () => {
expect(fixture.innerHTML).toBe("<div>txttxt<div></div></div>");
});
test("t-on with handler bound to dynamic argument on a t-foreach", async () => {
expect.assertions(3);
env.qweb.addTemplates(`
<templates>
<div t-name="ParentWidget">
<t t-foreach="props.items" t-as="item">
<Child t-key="item" t-on-ev="onEv(item)"/>
</t>
</div>
</templates>
`);
const items = [1, 2, 3, 4];
class ParentWidget extends Widget {
components = { Child };
onEv(n, ev) {
expect(n).toBe(1);
expect(ev.detail).toBe(43);
}
}
class Child extends Widget {}
const widget = new ParentWidget(env, { items });
await widget.mount(fixture);
children(widget)[0].trigger("ev", 43);
expect(env.qweb.templates.ParentWidget.fn.toString()).toMatchSnapshot();
});
test("updating widget immediately", async () => {
// in this situation, we protect against a bug that occurred: because of the
// interplay between components and vnodes, a sub widget vnode was patched