summaryrefslogtreecommitdiff
path: root/addons/web/static/tests
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2021-02-10 09:03:08 +0000
committerAaron Bohy <aab@odoo.com>2021-02-10 14:17:09 +0000
commit7e45dd0b8fc2d94eb992e67206f18cd4400f4a33 (patch)
tree595ebad1981ce6f078eb360751793459c715f16b /addons/web/static/tests
parent2385e58d76aa5e4bca0fc6d76ecedc7de5fd4267 (diff)
[FIX] web: call do_hide/do_show on a destroyed widget
Before this commit, calling do_hide/do_show/do_toggle on a widget that had been destroyed before being rendered crashed (because this.$el was undefined). Obviously, calling those methods in this situation is useless, but with asynchronous code, it might happen that you call them in an handler, and they have been destroyed meanwhile. This commit checks if this.$el is set before accessing it to avoid the crash. closes odoo/odoo#65889 X-original-commit: 320c29f5b37d4f02b4d5f7b1b6ff64462b000c92 Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Diffstat (limited to 'addons/web/static/tests')
-rw-r--r--addons/web/static/tests/core/widget_tests.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/addons/web/static/tests/core/widget_tests.js b/addons/web/static/tests/core/widget_tests.js
index 1c1c59f1d52..dc704abe274 100644
--- a/addons/web/static/tests/core/widget_tests.js
+++ b/addons/web/static/tests/core/widget_tests.js
@@ -450,6 +450,27 @@ QUnit.module('core', {}, function () {
parent.destroy();
});
+ QUnit.test("calling do_hide on a widget destroyed before being rendered", async function (assert) {
+ assert.expect(1);
+
+ const MyWidget = Widget.extend({
+ willStart() {
+ return new Promise(() => {});
+ }
+ });
+
+ const widget = new MyWidget();
+ widget.appendTo(document.createDocumentFragment());
+ widget.destroy();
+
+ // those calls should not crash
+ widget.do_hide();
+ widget.do_show();
+ widget.do_toggle(true);
+
+ assert.ok(true);
+ });
+
QUnit.test('start is not called when widget is destroyed', function (assert) {
assert.expect(0);
const $fix = $("#qunit-fixture");