[FIX] web: use same date in object test

Before this commit, a test in the "objects" test suite failed because
the 2 dates generated to verify equality could potentially be created
in a different millisecond, which would make the test fail.

A first fix simply assumed that patching the date would suffice, but
this did not solve the issue since the time advances normally even for
patched dates.

This fix ensures that the dates have exactly the same values (and
removes the patch which was not necessary anyway).

Runbot task 25596

closes odoo/odoo#139953

X-original-commit: b02d7fe6c4eaee09066cf58d0e9bad91e3a3234d
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
This commit is contained in:
Julien Mougenot
2023-10-27 13:02:22 +00:00
parent 3b1d10f0f1
commit 43640ceb1c
@@ -1,7 +1,6 @@
/** @odoo-module **/
import { omit, pick, shallowEqual } from "@web/core/utils/objects";
import { patchDate } from "@web/../tests/helpers/utils";
QUnit.module("utils", () => {
QUnit.module("Objects");
@@ -60,11 +59,12 @@ QUnit.module("utils", () => {
});
QUnit.test("shallowEqual: custom comparison function", function (assert) {
patchDate(2019, 2, 11, 12, 30, 0);
const dateA = new Date();
const dateB = new Date(dateA);
assert.notOk(shallowEqual({ a: 1, date: new Date() }, { a: 1, date: new Date() }));
assert.notOk(shallowEqual({ a: 1, date: dateA }, { a: 1, date: dateB }));
assert.ok(
shallowEqual({ a: 1, date: new Date() }, { a: 1, date: new Date() }, (a, b) =>
shallowEqual({ a: 1, date: dateA }, { a: 1, date: dateB }, (a, b) =>
a instanceof Date ? Number(a) === Number(b) : a === b
)
);