Skip to content

Commit 1bf375c

Browse files
committed
[FIX] misc: Fix deepEquals behaviour
Since PR 4066, we can compare objects while ignoring functions inside them as the function references might differ. However, the implementation was faulty and would mistakenly consider two object to be equals as soon as they both contained a function for the same key. closes #4245 Task: 3942782 Signed-off-by: Adrien Minne (adrm) <[email protected]>
1 parent ca535ad commit 1bf375c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/helpers/misc.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ export function deepEquals(o1: any, o2: any, ignoreFunctions?: "ignoreFunctions"
369369
if (typeOfO1Key === "object") {
370370
if (!deepEquals(o1[key], o2[key], ignoreFunctions)) return false;
371371
} else {
372-
if (ignoreFunctions && typeOfO1Key === "function") return true;
372+
if (ignoreFunctions && typeOfO1Key === "function") {
373+
continue;
374+
}
373375
if (o1[key] !== o2[key]) return false;
374376
}
375377
}

tests/helpers/misc_helpers.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,16 @@ test.each([
234234
});
235235

236236
test("deepEquals with argument ignoring functions", () => {
237-
const o1 = { a: 1, b: () => 2 };
238-
const o2 = { a: 1, b: () => 2 };
237+
const o1 = { a: 1, b: () => 2, c: 2 };
238+
const o2 = { a: 1, b: () => 2, c: 2 };
239+
const o3 = { a: 1, b: () => 2, c: 3 };
240+
const o4 = { a: 2, b: () => 2, c: 2 };
239241
expect(deepEquals(o1, o2)).toEqual(false);
240242
expect(deepEquals(o1, o2, "ignoreFunctions")).toEqual(true);
243+
expect(deepEquals(o1, o3)).toEqual(false);
244+
expect(deepEquals(o1, o3, "ignoreFunctions")).toEqual(false);
245+
expect(deepEquals(o1, o4)).toEqual(false);
246+
expect(deepEquals(o1, o4, "ignoreFunctions")).toEqual(false);
241247
});
242248

243249
describe("isConsecutive", () => {

0 commit comments

Comments
 (0)