mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] components: capture context in prop expressions
This commit is contained in:
committed by
Aaron Bohy
parent
c0cf2c9e3d
commit
7143dd3ff5
@@ -102,4 +102,29 @@ describe("basics", () => {
|
||||
await mount(Parent, fixture);
|
||||
expect(fixture.innerHTML).toBe("<div><span><p>43</p><p>43</p></span></div>");
|
||||
});
|
||||
|
||||
test("arrow functions as prop correctly capture their scope", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`<button t-on-click="props.onClick"/>`;
|
||||
}
|
||||
|
||||
let onClickArgs: [number, MouseEvent] | null = null;
|
||||
class Parent extends Component {
|
||||
static template = xml`
|
||||
<t t-foreach="items" t-as="item" t-key="item.val">
|
||||
<Child onClick="ev => onClick(item.val, ev)"/>
|
||||
</t>
|
||||
`;
|
||||
static components = { Child };
|
||||
items = [{ val: 1 }, { val: 2 }, { val: 3 }, { val: 4 }];
|
||||
onClick(n: number, ev: MouseEvent) {
|
||||
onClickArgs = [n, ev];
|
||||
}
|
||||
}
|
||||
await mount(Parent, fixture);
|
||||
expect(onClickArgs).toBeNull();
|
||||
(<HTMLElement>fixture.querySelector("button")).click();
|
||||
expect(onClickArgs![0]).toBe(1);
|
||||
expect(onClickArgs![1]).toBeInstanceOf(MouseEvent);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user