Skip to content

Commit a62506e

Browse files
doc: clarify behavior of destructured assertion methods in Assert instance
1 parent 965c35f commit a62506e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/api/assert.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,21 @@ assertInstance.deepStrictEqual({ a: 1 }, { a: 2 });
242242
// Shows a full diff in the error message.
243243
```
244244

245+
**Important**: When destructuring assertion methods from an `Assert` instance, the methods lose their connection to the instance's configuration options (such as `diff` and `strict` settings). The destructured methods will behave with default options instead.
246+
247+
```js
248+
const myAssert = new Assert({ diff: 'full' });
249+
250+
// This works as expected - uses 'full' diff
251+
myAssert.strictEqual({ a: 1 }, { b: { c: 1 } });
252+
253+
// This loses the 'full' diff setting - uses default 'simple' diff
254+
const { strictEqual } = myAssert;
255+
strictEqual({ a: 1 }, { b: { c: 1 } });
256+
```
257+
258+
To maintain custom options when using destructured methods, pass the options to individual assertion calls or avoid destructuring.
259+
245260
## `assert(value[, message])`
246261

247262
<!-- YAML

0 commit comments

Comments
 (0)