Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
lib: update skipPrototypeComparison to skipPrototype
  • Loading branch information
miguelmarcondesf committed Sep 10, 2025
commit 0ae19100b24d3aa73ff68e91b5a9e6b65ce12c77
10 changes: 5 additions & 5 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ The `Assert` class allows creating independent assertion instances with custom o
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/59762
description: Added `skipPrototypeComparison` option.
description: Added `skipPrototype` option.
-->

* `options` {Object}
* `diff` {string} If set to `'full'`, shows the full diff in assertion errors. Defaults to `'simple'`.
Accepted values: `'simple'`, `'full'`.
* `strict` {boolean} If set to `true`, non-strict methods behave like their
corresponding strict methods. Defaults to `true`.
* `skipPrototypeComparison` {boolean} If set to `true`, skips prototype and constructor
* `skipPrototype` {boolean} If set to `true`, skips prototype and constructor
comparison in deep equality checks. Defaults to `false`.

Creates a new assertion instance. The `diff` option controls the verbosity of diffs in assertion error messages.
Expand All @@ -255,7 +255,7 @@ assertInstance.deepStrictEqual({ a: 1 }, { a: 2 });

**Important**: When destructuring assertion methods from an `Assert` instance,
the methods lose their connection to the instance's configuration options (such
as `diff`, `strict`, and `skipPrototypeComparison` settings).
as `diff`, `strict`, and `skipPrototype` settings).
The destructured methods will fall back to default behavior instead.

```js
Expand All @@ -269,7 +269,7 @@ const { strictEqual } = myAssert;
strictEqual({ a: 1 }, { b: { c: 1 } });
```

The `skipPrototypeComparison` option affects all deep equality methods:
The `skipPrototype` option affects all deep equality methods:

```js
class Foo {
Expand All @@ -292,7 +292,7 @@ const assert1 = new Assert();
assert1.deepStrictEqual(foo, bar); // AssertionError

// Skip prototype comparison - passes if properties are equal
Comment thread
ljharb marked this conversation as resolved.
const assert2 = new Assert({ skipPrototypeComparison: true });
const assert2 = new Assert({ skipPrototype: true });
assert2.deepStrictEqual(foo, bar); // OK
```

Expand Down
4 changes: 2 additions & 2 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -1565,15 +1565,15 @@ changes:

* `val1` {any}
* `val2` {any}
* `skipPrototypeComparison` {boolean} If `true`, prototype and constructor
* `skipPrototype` {boolean} If `true`, prototype and constructor
comparison is skipped during deep strict equality check. **Default:** `false`.
* Returns: {boolean}

Returns `true` if there is deep strict equality between `val1` and `val2`.
Otherwise, returns `false`.

By default, deep strict equality includes comparison of object prototypes and
constructors. When `skipPrototypeComparison` is `true`, objects with
constructors. When `skipPrototype` is `true`, objects with
different prototypes or constructors can still be considered equal if their
enumerable properties are deeply strictly equal.

Expand Down
8 changes: 4 additions & 4 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const NO_EXCEPTION_SENTINEL = {};
* @property {'full'|'simple'} [diff='simple'] - If set to 'full', shows the full diff in assertion errors.
* @property {boolean} [strict=true] - If set to true, non-strict methods behave like their corresponding
* strict methods.
* @property {boolean} [skipPrototypeComparison=false] - If set to true, skips comparing prototypes
* @property {boolean} [skipPrototype=false] - If set to true, skips comparing prototypes
* in deep equality checks.
*/

Expand All @@ -107,7 +107,7 @@ function Assert(options) {
throw new ERR_CONSTRUCT_CALL_REQUIRED('Assert');
}

options = ObjectAssign({ __proto__: null, strict: true, skipPrototypeComparison: false }, options);
options = ObjectAssign({ __proto__: null, strict: true, skipPrototype: false }, options);

const allowedDiffs = ['simple', 'full'];
if (options.diff !== undefined) {
Expand Down Expand Up @@ -313,7 +313,7 @@ Assert.prototype.deepStrictEqual = function deepStrictEqual(actual, expected, me
throw new ERR_MISSING_ARGS('actual', 'expected');
}
if (isDeepEqual === undefined) lazyLoadComparison();
if (!isDeepStrictEqual(actual, expected, this?.[kOptions]?.skipPrototypeComparison)) {
if (!isDeepStrictEqual(actual, expected, this?.[kOptions]?.skipPrototype)) {
innerFail({
actual,
expected,
Expand All @@ -339,7 +339,7 @@ function notDeepStrictEqual(actual, expected, message) {
throw new ERR_MISSING_ARGS('actual', 'expected');
}
if (isDeepEqual === undefined) lazyLoadComparison();
if (isDeepStrictEqual(actual, expected, this?.[kOptions]?.skipPrototypeComparison)) {
if (isDeepStrictEqual(actual, expected, this?.[kOptions]?.skipPrototype)) {
innerFail({
actual,
expected,
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,8 @@ module.exports = {
isDeepEqual(val1, val2) {
return detectCycles(val1, val2, kLoose);
},
isDeepStrictEqual(val1, val2, skipPrototypeComparison) {
if (skipPrototypeComparison) {
isDeepStrictEqual(val1, val2, skipPrototype) {
if (skipPrototype) {
return detectCycles(val1, val2, kStrictWithoutPrototypes);
}
return detectCycles(val1, val2, kStrict);
Expand Down
4 changes: 2 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,11 @@ module.exports = {
isArray: deprecate(ArrayIsArray,
'The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.',
'DEP0044'),
isDeepStrictEqual(a, b, skipPrototypeComparison) {
isDeepStrictEqual(a, b, skipPrototype) {
if (internalDeepEqual === undefined) {
internalDeepEqual = require('internal/util/comparisons').isDeepStrictEqual;
}
return internalDeepEqual(a, b, skipPrototypeComparison);
return internalDeepEqual(a, b, skipPrototype);
},
promisify,
stripVTControlCharacters,
Expand Down
28 changes: 14 additions & 14 deletions test/parallel/test-assert-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ test('Assert class non strict with simple diff', () => {
}
});

// Shared setup for skipPrototypeComparison tests
// Shared setup for skipPrototype tests
{
const message = 'Expected values to be strictly deep-equal:\n' +
'+ actual - expected\n' +
Expand Down Expand Up @@ -507,8 +507,8 @@ test('Assert class non strict with simple diff', () => {
const modern = new Modern(42);
const legacy = new Legacy(42);

test('Assert class strict with skipPrototypeComparison', () => {
const assertInstance = new Assert({ skipPrototypeComparison: true });
test('Assert class strict with skipPrototype', () => {
const assertInstance = new Assert({ skipPrototype: true });

assert.throws(
() => assertInstance.deepEqual([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 9, 7]),
Expand All @@ -535,8 +535,8 @@ test('Assert class non strict with simple diff', () => {
assertInstance.deepStrictEqual(arr, buf);
});

test('Assert class non strict with skipPrototypeComparison', () => {
const assertInstance = new Assert({ strict: false, skipPrototypeComparison: true });
test('Assert class non strict with skipPrototype', () => {
const assertInstance = new Assert({ strict: false, skipPrototype: true });

assert.throws(
() => assertInstance.deepStrictEqual([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 9, 7]),
Expand All @@ -547,8 +547,8 @@ test('Assert class non strict with simple diff', () => {
assertInstance.deepStrictEqual(modern, legacy);
});

test('Assert class skipPrototypeComparison with complex objects', () => {
const assertInstance = new Assert({ skipPrototypeComparison: true });
test('Assert class skipPrototype with complex objects', () => {
const assertInstance = new Assert({ skipPrototype: true });

function ComplexAwesomeClass(name, age) {
this.name = name;
Expand Down Expand Up @@ -582,8 +582,8 @@ test('Assert class non strict with simple diff', () => {
);
});

test('Assert class skipPrototypeComparison with arrays and special objects', () => {
const assertInstance = new Assert({ skipPrototypeComparison: true });
test('Assert class skipPrototype with arrays and special objects', () => {
const assertInstance = new Assert({ skipPrototype: true });

const arr1 = [1, 2, 3];
const arr2 = new Array(1, 2, 3);
Expand All @@ -604,8 +604,8 @@ test('Assert class non strict with simple diff', () => {
);
});

test('Assert class skipPrototypeComparison with notDeepStrictEqual', () => {
const assertInstance = new Assert({ skipPrototypeComparison: true });
test('Assert class skipPrototype with notDeepStrictEqual', () => {
const assertInstance = new Assert({ skipPrototype: true });

assert.throws(
() => assertInstance.notDeepStrictEqual(cool, awesome),
Expand All @@ -615,12 +615,12 @@ test('Assert class non strict with simple diff', () => {
const notAwesome = new AwesomeClass('Not so awesome');
assertInstance.notDeepStrictEqual(cool, notAwesome);

const defaultAssertInstance = new Assert({ skipPrototypeComparison: false });
const defaultAssertInstance = new Assert({ skipPrototype: false });
defaultAssertInstance.notDeepStrictEqual(cool, awesome);
});

test('Assert class skipPrototypeComparison with mixed types', () => {
const assertInstance = new Assert({ skipPrototypeComparison: true });
test('Assert class skipPrototype with mixed types', () => {
const assertInstance = new Assert({ skipPrototype: true });

const obj1 = { value: 42, nested: { prop: 'test' } };

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-util-isDeepStrictEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ function notUtilIsDeepStrict(a, b) {
utilIsDeepStrict(a, b);
}

// Handle `skipPrototypeComparison` for isDeepStrictEqual
// Handle `skipPrototype` for isDeepStrictEqual
{
test('util.isDeepStrictEqual with skipPrototypeComparison', () => {
test('util.isDeepStrictEqual with skipPrototype', () => {
function ClassA(value) { this.value = value; }

function ClassB(value) { this.value = value; }
Expand All @@ -123,7 +123,7 @@ function notUtilIsDeepStrict(a, b) {
assert.strictEqual(util.isDeepStrictEqual(uint8Array, buffer, true), true);
});

test('util.isDeepStrictEqual skipPrototypeComparison with complex scenarios', () => {
test('util.isDeepStrictEqual skipPrototype with complex scenarios', () => {
class Parent { constructor(x) { this.x = x; } }
class Child extends Parent { constructor(x, y) { super(x); this.y = y; } }

Expand Down
Loading