mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] app: t_call recursive template is bound to the correct this
This commit is contained in:
committed by
Aaron Bohy
parent
cec451fd15
commit
281b32965e
@@ -206,4 +206,42 @@ describe("t-call", () => {
|
||||
|
||||
expect(fixture.innerHTML).toBe(`<div id="0"></div><div id="1"></div>`);
|
||||
});
|
||||
|
||||
test("recursive t-call binding this -- static t-call", async () => {
|
||||
let clickCount = 0;
|
||||
class Parent extends Component {
|
||||
onClicked?: Function;
|
||||
setup() {
|
||||
const instance = this;
|
||||
|
||||
this.onClicked = function () {
|
||||
clickCount++;
|
||||
expect(this).toBe(instance);
|
||||
};
|
||||
}
|
||||
|
||||
static template = xml`
|
||||
<div><t t-call="recursive"><t t-set="level" t-value="0" /></t></div>
|
||||
`;
|
||||
}
|
||||
|
||||
const app = new App(Parent);
|
||||
app.addTemplate(
|
||||
"recursive",
|
||||
`
|
||||
<t t-if="level < 2" >
|
||||
<div t-on-click.stop="onClicked.bind(this)" t-esc="level" />
|
||||
<t t-call="recursive">
|
||||
<t t-set="level" t-value="level + 1" />
|
||||
</t>
|
||||
</t>
|
||||
`
|
||||
);
|
||||
|
||||
await app.mount(fixture);
|
||||
for (const div of fixture.querySelectorAll("div")) {
|
||||
div.click();
|
||||
}
|
||||
expect(clickCount).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user