Skip to content

Commit cb15c34

Browse files
authored
fix: remove needless check for equalCompare after Object.is (#15085)
1 parent 3a7a9c0 commit cb15c34

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/expect-utils/src/__tests__/utils.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,26 @@ describe('arrayBufferEquality', () => {
703703
expect(equals(a, b)).toBeFalsy();
704704
});
705705
});
706+
707+
describe('jasmineUtils primitives comparison', () => {
708+
const falseCases: Array<[any, any]> = [
709+
[null, undefined],
710+
[null, 0],
711+
[false, 0],
712+
[false, ''],
713+
];
714+
715+
for (const [a, b] of falseCases) {
716+
test(`${JSON.stringify(a)} and ${JSON.stringify(b)} returns false`, () => {
717+
expect(equals(a, b)).toBe(false);
718+
});
719+
}
720+
721+
const trueCases: Array<any> = [null, 0, false, '', undefined];
722+
723+
for (const value of trueCases) {
724+
test(`${JSON.stringify(value)} returns true`, () => {
725+
expect(equals(value, value)).toBe(true);
726+
});
727+
}
728+
});

packages/expect-utils/src/jasmineUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function eq(
9292
}
9393
// A strict comparison is necessary because `null == undefined`.
9494
if (a === null || b === null) {
95-
return a === b;
95+
return false;
9696
}
9797
const className = Object.prototype.toString.call(a);
9898
if (className != Object.prototype.toString.call(b)) {
@@ -107,7 +107,7 @@ function eq(
107107
return false;
108108
} else if (typeof a !== 'object' && typeof b !== 'object') {
109109
// both are proper primitives
110-
return Object.is(a, b);
110+
return false;
111111
} else {
112112
// both are `new Primitive()`s
113113
return Object.is(a.valueOf(), b.valueOf());

0 commit comments

Comments
 (0)