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
committerGéry Debongnie <ged@odoo.com>2017-12-18 17:29:13 +0100
commitfa9f58d6ced2e18403506b1b59a8de2734d71671 (patch)
tree2584391bcf0b291c20f2fdcd2805a2319d07393e /addons/web/static/tests/fields/relational_fields_tests.js
parent5e70e949d566269ae8df9ead7f8cc5aff790bbc0 (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 0739a6252ca..fb10cf6d784 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -4065,16 +4065,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;
@@ -4161,8 +4161,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) {