From 91896942ddb3006b1ec824e34b33bd7c7827e601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 6 May 2019 13:45:50 +0200 Subject: [PATCH] [FIX] component: prevent rendering if not mounted --- src/component.ts | 2 +- tests/component.test.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/component.ts b/src/component.ts index c104ed58..c7cae77c 100644 --- a/src/component.ts +++ b/src/component.ts @@ -238,7 +238,7 @@ export class Component< } async render(force: boolean = false, patchQueue?: any[]): Promise { - if (this.__owl__.isDestroyed) { + if (!this.__owl__.isMounted) { return; } const shouldCallPatchHooks: boolean = !patchQueue; diff --git a/tests/component.test.ts b/tests/component.test.ts index 82901c1d..8204358f 100644 --- a/tests/component.test.ts +++ b/tests/component.test.ts @@ -87,6 +87,16 @@ describe("basic widget properties", () => { }); test("can be clicked on and updated", async () => { + const counter = new Counter(env); + await counter.mount(fixture); + expect(fixture.innerHTML).toBe("
0
"); + const button = (counter.el).getElementsByTagName("button")[0]; + await button.click(); + await nextTick(); + expect(fixture.innerHTML).toBe("
1
"); + }); + + test("cannot be clicked on and updated if not in DOM", async () => { const counter = new Counter(env); const target = document.createElement("div"); await counter.mount(target); @@ -94,7 +104,8 @@ describe("basic widget properties", () => { const button = (counter.el).getElementsByTagName("button")[0]; await button.click(); await nextTick(); - expect(target.innerHTML).toBe("
1
"); + expect(target.innerHTML).toBe("
0
"); + expect(counter.state.counter).toBe(1); }); test("widget style and classname", async () => {