[IMP] component: add 'set' method to allow extending state

closes #49
This commit is contained in:
Géry Debongnie
2019-04-18 10:15:50 +02:00
parent 3b3fd8a6c9
commit 4ee39282ca
2 changed files with 19 additions and 0 deletions
+15
View File
@@ -1449,4 +1449,19 @@ describe("widget and observable state", () => {
);
}
});
test("widget can add observed keys to its state", async () => {
class TestWidget extends Widget {
state: any = { a: 1 };
inlineTemplate = `<div><t t-esc="state.a"/><t t-esc="state.b"/></div>`;
}
const widget = new TestWidget(env);
await widget.mount(fixture);
expect(fixture.innerHTML).toBe("<div>1</div>");
widget.set(widget.state, "b", 2);
await nextTick();
expect(fixture.innerHTML).toBe("<div>12</div>");
});
});