prevent useless rerenders when updatingEnv on unmounted component

fix #4
This commit is contained in:
Géry Debongnie
2019-03-21 10:37:49 +01:00
parent b446d5d338
commit d799e3dd47
2 changed files with 26 additions and 1 deletions
+23
View File
@@ -1096,6 +1096,29 @@ describe("updating environment", () => {
expect((<any>widget).env.somekey).toBe(4);
});
test("updating widget env does not render widget (if not mounted)", async () => {
let n = 0;
class TestWidget extends Widget {
_render() {
n++;
return super._render();
}
}
const widget = new TestWidget(env);
expect(n).toBe(0);
await widget.updateEnv(<any>{ somekey: 4 });
expect(n).toBe(0);
await widget.mount(fixture);
expect(n).toBe(1);
await widget.updateEnv(<any>{ somekey: 5 });
expect(n).toBe(2);
widget.detach();
expect(n).toBe(2);
await widget.updateEnv(<any>{ somekey: 5 });
expect(n).toBe(2);
});
test("updating child env does not modify parent env", async () => {
class ParentWidget extends Widget {
inlineTemplate = `<div><t t-widget="child"/></div>`;