Skip to content

Commit b4d8d5e

Browse files
doc: add skipPrototypeComparison option to Assert class
1 parent e246295 commit b4d8d5e

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

doc/api/assert.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,20 @@ The `Assert` class allows creating independent assertion instances with custom o
229229

230230
### `new assert.Assert([options])`
231231

232+
<!-- YAML
233+
changes:
234+
- version: REPLACEME
235+
pr-url: https://github.com/nodejs/node/pull/00000
236+
description: Added `skipPrototypeComparison` option.
237+
-->
238+
232239
* `options` {Object}
233240
* `diff` {string} If set to `'full'`, shows the full diff in assertion errors. Defaults to `'simple'`.
234241
Accepted values: `'simple'`, `'full'`.
235242
* `strict` {boolean} If set to `true`, non-strict methods behave like their
236243
corresponding strict methods. Defaults to `true`.
244+
* `skipPrototypeComparison` {boolean} If set to `true`, skips prototype and constructor
245+
comparison in deep equality checks. Defaults to `false`.
237246

238247
Creates a new assertion instance. The `diff` option controls the verbosity of diffs in assertion error messages.
239248

@@ -245,7 +254,8 @@ assertInstance.deepStrictEqual({ a: 1 }, { a: 2 });
245254
```
246255

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

251261
```js
@@ -259,6 +269,25 @@ const { strictEqual } = myAssert;
259269
strictEqual({ a: 1 }, { b: { c: 1 } });
260270
```
261271

272+
The `skipPrototypeComparison` option affects all deep equality methods:
273+
274+
```js
275+
function Foo(a) { this.a = a; }
276+
277+
function Bar(a) { this.a = a; }
278+
279+
const foo = new Foo(1);
280+
const bar = new Bar(1);
281+
282+
// Default behavior - fails due to different constructors
283+
const assert1 = new Assert();
284+
assert1.deepStrictEqual(foo, bar); // AssertionError
285+
286+
// Skip prototype comparison - passes if properties are equal
287+
const assert2 = new Assert({ skipPrototypeComparison: true });
288+
assert2.deepStrictEqual(foo, bar); // OK
289+
```
290+
262291
When destructured, methods lose access to the instance's `this` context and revert to default assertion behavior
263292
(diff: 'simple', non-strict mode).
264293
To maintain custom options when using destructured methods, avoid

0 commit comments

Comments
 (0)