mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component: add support for callable expression in event handler
This commit is contained in:
committed by
Géry Debongnie
parent
3e0e8475a6
commit
7ebe0da962
@@ -149,6 +149,24 @@ describe("basic widget properties", () => {
|
||||
expect(fixture.innerHTML).toBe("<div>1<button>Inc</button></div>");
|
||||
});
|
||||
|
||||
test("support for callable expression in event handler", async () => {
|
||||
class Counter extends Component {
|
||||
static template = xml`
|
||||
<div><t t-esc="state.value"/><input type="text" t-on-input="obj.onInput"/></div>`;
|
||||
state = useState({ value: "" });
|
||||
obj = { onInput: (ev) => (this.state.value = ev.target.value) };
|
||||
}
|
||||
|
||||
const counter = await mount(Counter, { target: fixture });
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(`<div><input type="text"></div>`);
|
||||
const input = (<HTMLElement>counter.el).getElementsByTagName("input")[0];
|
||||
input.value = "test";
|
||||
input.dispatchEvent(new Event("input"));
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(`<div>test<input type="text"></div>`);
|
||||
});
|
||||
|
||||
test("can handle empty props", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`<span><t t-esc="props.val"/></span>`;
|
||||
|
||||
Reference in New Issue
Block a user