From 0c98951f1ceea0104d06cd0e543cf32fc1c34f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 18 Dec 2017 14:29:02 +0100 Subject: [PATCH] [FIX] barcodes: use patch to prevent interactions between tests There is a subtle issue happening in tests when we override a widget property for the duration of the test and try to restore the initial state at the end by rewriting on the property. It actually changes the widget, by having a function bound to the sub widget prototype instead of its ancestor. This in turns can cause weird interactions with the class system. We introduced a proper way to temporarily patch a class/widget by adding a method in testUtils to do exactly that. This commit simply uses that method to prevent unwanted interactions in barcode tests --- addons/barcodes/static/tests/barcode_tests.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/barcodes/static/tests/barcode_tests.js b/addons/barcodes/static/tests/barcode_tests.js index 56d11af9b9a..cf77497a2a7 100644 --- a/addons/barcodes/static/tests/barcode_tests.js +++ b/addons/barcodes/static/tests/barcode_tests.js @@ -164,11 +164,12 @@ QUnit.test('do no update form twice after a command barcode scanned', function ( var delay = barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms; barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = 0; - var formUpdate = FormController.prototype.update; - FormController.prototype.update = function () { - assert.step('update'); - return formUpdate.apply(this, arguments); - }; + testUtils.patch(FormController, { + update: function () { + assert.step('update'); + return this._super.apply(this, arguments); + }, + }); var form = createView({ View: FormView, @@ -206,7 +207,7 @@ QUnit.test('do no update form twice after a command barcode scanned', function ( form.destroy(); barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = delay; - FormController.prototype.update = formUpdate; + testUtils.unpatch(FormController); }); QUnit.test('widget field_float_scannable', function (assert) {