diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index b58b828a96..3b800b48b7 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -304,9 +304,9 @@ function objectComparisonStart(val1, val2, mode, memos) { } const time1 = DatePrototypeGetTime(val1); const time2 = DatePrototypeGetTime(val2); - if (time1 !== time2) { - // eslint-disable-next-line no-self-compare - return time1 !== time1 && time2 !== time2; + // eslint-disable-next-line no-self-compare + if (time1 !== time2 && (time1 === time1 || time2 === time2)) { + return false; } } else if (isRegExp(val1)) { if (!isRegExp(val2) || !areSimilarRegExps(val1, val2)) { diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index 73da19017a..9c1d8eefe0 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -752,7 +752,18 @@ test('Additional tests', () => { assertNotDeepOrStrict(new Date(), new Date(2000, 3, 14)); - assertDeepAndStrictEqual(new Date('foo'), new Date('bar')); + { + // Invalid dates deep comparison. + const date1 = new Date('foo'); + const date2 = new Date('bar'); + date1.foo = true; + date2.foo = true; + assertDeepAndStrictEqual(date1, date2); + + date1.bar = false; + date2.bar = true; + assertNotDeepOrStrict(date1, date2); + } assertDeepAndStrictEqual(/a/, /a/); assertDeepAndStrictEqual(/a/g, /a/g);