Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions benchmark/assert/deepequal-prims-and-objs-big-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const primValues = {
'empty_object': {},
'regexp': /abc/i,
'date': new Date(),
'invalidDate': new Date('foo'),
};

const primValues2 = {
Expand All @@ -34,6 +35,7 @@ const primValues2 = {
'empty_object': {},
'regexp': /abc/i,
'date': new Date(primValues.date),
'invalidDate': new Date('foo'),
};

const primValuesUnequal = {
Expand All @@ -49,6 +51,7 @@ const primValuesUnequal = {
'empty_object': [],
'regexp': /abc/g,
'date': new Date(primValues.date.getTime() + 1),
'invalidDate': new Date(),
};

const bench = common.createBenchmark(main, {
Expand Down
15 changes: 12 additions & 3 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@
<!-- YAML
added: v0.1.21
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57627
description: Invalid dates are now considered equal.
- version: v24.0.0
pr-url: https://github.com/nodejs/node/pull/57622
description: Recursion now stops when either side encounters a circular
Expand Down Expand Up @@ -422,6 +425,9 @@
<!-- YAML
added: v1.2.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57627
description: Invalid dates are now considered equal.
- version: v24.0.0
pr-url: https://github.com/nodejs/node/pull/57622
description: Recursion now stops when either side encounters a circular
Expand Down Expand Up @@ -2278,9 +2284,12 @@
- v23.4.0
- v22.13.0
changes:
- version: v24.0.0
pr-url: https://github.com/nodejs/node/pull/57370
description: partialDeepStrictEqual is now Stable. Previously, it had been Experimental.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57627
description: Invalid dates are now considered equal.
- version: v24.0.0
pr-url: https://github.com/nodejs/node/pull/57370

Check warning on line 2291 in doc/api/assert.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: partialDeepStrictEqual is now Stable. Previously, it had been Experimental.
-->

* `actual` {any}
Expand Down
9 changes: 7 additions & 2 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,15 @@ function objectComparisonStart(val1, val2, mode, memos) {
} else if (val1Tag === '[object Object]') {
return keyCheck(val1, val2, mode, memos, kNoIterator);
} else if (isDate(val1)) {
if (!isDate(val2) ||
DatePrototypeGetTime(val1) !== DatePrototypeGetTime(val2)) {
if (!isDate(val2)) {
return false;
}
const time1 = DatePrototypeGetTime(val1);
const time2 = DatePrototypeGetTime(val2);
if (time1 !== time2) {
// eslint-disable-next-line no-self-compare
return time1 !== time1 && time2 !== time2;
}
} else if (isRegExp(val1)) {
if (!isRegExp(val2) || !areSimilarRegExps(val1, val2)) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,8 @@ test('Additional tests', () => {

assertNotDeepOrStrict(new Date(), new Date(2000, 3, 14));

assertDeepAndStrictEqual(new Date('foo'), new Date('bar'));

assertDeepAndStrictEqual(/a/, /a/);
assertDeepAndStrictEqual(/a/g, /a/g);
assertDeepAndStrictEqual(/a/i, /a/i);
Expand Down
Loading