summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/helpers/test_utils_tests.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2019-08-01 09:22:57 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2019-08-13 07:57:10 +0000
commit7d8977182bb8acaa68d6b055db619f94196edbfd (patch)
tree6b9c6c77069e2e60610881455c89940959ee97fb /addons/web/static/tests/helpers/test_utils_tests.js
parent02903076c9d7dfe0adf3f555ac650d72c5667608 (diff)
[IMP] web:tests: patch `Date.now`
Before this commit, when we use `testUtils.patchDate`, the function `Date.now` was not using the fake date for reference. This is an issue with the lib momentjs, which instantiate the current date as follow: ``` new Date(Date.now()) ``` Because of this, we were handling patched date and unpatched moment objects. Task-ID 1902848
Diffstat (limited to 'addons/web/static/tests/helpers/test_utils_tests.js')
-rw-r--r--addons/web/static/tests/helpers/test_utils_tests.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/addons/web/static/tests/helpers/test_utils_tests.js b/addons/web/static/tests/helpers/test_utils_tests.js
new file mode 100644
index 00000000000..d4f386625f7
--- /dev/null
+++ b/addons/web/static/tests/helpers/test_utils_tests.js
@@ -0,0 +1,36 @@
+odoo.define('web.testUtilsTests', function (require) {
+"use strict";
+
+var testUtils = require('web.test_utils');
+
+QUnit.module('web', {}, function () {
+QUnit.module('testUtils', {}, function () {
+
+QUnit.module('patch date');
+
+QUnit.test('new date', function (assert) {
+ assert.expect(5);
+ const unpatchDate = testUtils.mock.patchDate(2018, 9, 23, 14, 50, 0);
+
+ const date = new Date();
+
+ assert.strictEqual(date.getFullYear(), 2018);
+ assert.strictEqual(date.getMonth(), 9);
+ assert.strictEqual(date.getDate(), 23);
+ assert.strictEqual(date.getHours(), 14);
+ assert.strictEqual(date.getMinutes(), 50);
+ unpatchDate();
+});
+
+QUnit.test('new moment', function (assert) {
+ assert.expect(1);
+ const unpatchDate = testUtils.mock.patchDate(2018, 9, 23, 14, 50, 0);
+
+ const m = moment();
+ assert.strictEqual(m.format('YYYY-MM-DD HH:mm'), '2018-10-23 14:50');
+ unpatchDate();
+});
+
+});
+});
+}); \ No newline at end of file