summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-12-07 14:06:29 +0100
committerAaron Bohy <aab@odoo.com>2017-12-15 13:07:34 +0100
commit377705aada34fd98ae92c39cb0a1f0151ee3f720 (patch)
treec8058273faec398f536341c1c3d1c133f832df83 /addons/web/static/tests/fields/relational_fields_tests.js
parent7f467d2346567943581dc1cc3e523ecfcc9b3b13 (diff)
[IMP] web: tests: add a way to properly mock Widgets
This rev. introduces two helper functions for the tests: patch and unpatch. Those function allow patching an Odoo Widget (e.g. AbstractField), and unpatch it at the end of the test with the guarantee that the Widget's prototype is exactly the same as it was before the test. This was necessary because the way it was done before was a little bit too naive, and could lead to unexpected behavior. Indeed, doing var someFunction = AbstractField.prototype.someFunction; // test content AbstractField.prototype.someFunction = someFunction; is correct if someFunction is actually define (or overriden) in AbstractField, as in that case, it really exists on its prototype. Otherwise, it isn't correct if it is not directly defined on the prototype before the test, as it will be after..
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js23
1 files changed, 11 insertions, 12 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 6dbe709a324..f7a63a18f9b 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -4040,16 +4040,16 @@ QUnit.module('relational_fields', {
assert.expect(5);
var delta = 0;
- var oldInit = AbstractField.prototype.init;
- var oldDestroy = AbstractField.prototype.destroy;
- AbstractField.prototype.init = function () {
- delta++;
- oldInit.apply(this, arguments);
- };
- AbstractField.prototype.destroy = function () {
- delta--;
- oldDestroy.apply(this, arguments);
- };
+ testUtils.patch(AbstractField, {
+ init: function () {
+ delta++;
+ this._super.apply(this, arguments);
+ },
+ destroy: function () {
+ delta--;
+ this._super.apply(this, arguments);
+ },
+ });
var deactiveOnchange = true;
@@ -4136,8 +4136,7 @@ QUnit.module('relational_fields', {
"should correctly refresh the records after save");
form.destroy();
- AbstractField.prototype.init = oldInit;
- AbstractField.prototype.destroy = oldDestroy;
+ testUtils.unpatch(AbstractField);
});
QUnit.test('one2many editable list with onchange keeps the order', function (assert) {