@types/node 16.4.1 → 16.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/assert.d.ts CHANGED
@@ -1,14 +1,28 @@
1
+ /**
2
+ * The `assert` module provides a set of assertion functions for verifying
3
+ * invariants.
4
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/assert.js)
5
+ */
1
6
  declare module 'assert' {
2
- /** An alias of `assert.ok()`. */
7
+ /**
8
+ * An alias of {@link ok}.
9
+ * @since v0.5.9
10
+ * @param value The input that is checked for being truthy.
11
+ */
3
12
  function assert(value: unknown, message?: string | Error): asserts value;
4
13
  namespace assert {
14
+ /**
15
+ * * Extends: `<errors.Error>`
16
+ *
17
+ * Indicates the failure of an assertion. All errors thrown by the `assert` module
18
+ * will be instances of the `AssertionError` class.
19
+ */
5
20
  class AssertionError extends Error {
6
21
  actual: unknown;
7
22
  expected: unknown;
8
23
  operator: string;
9
24
  generatedMessage: boolean;
10
25
  code: 'ERR_ASSERTION';
11
-
12
26
  constructor(options?: {
13
27
  /** If provided, the error message is set to this value. */
14
28
  message?: string | undefined;
@@ -23,11 +37,151 @@ declare module 'assert' {
23
37
  stackStartFn?: Function | undefined;
24
38
  });
25
39
  }
26
-
40
+ /**
41
+ * This feature is currently experimental and behavior might still change.
42
+ * @since v14.2.0, v12.19.0
43
+ * @experimental
44
+ */
27
45
  class CallTracker {
46
+ /**
47
+ * The wrapper function is expected to be called exactly `exact` times. If the
48
+ * function has not been called exactly `exact` times when `tracker.verify()` is called, then `tracker.verify()` will throw an
49
+ * error.
50
+ *
51
+ * ```js
52
+ * import assert from 'assert';
53
+ *
54
+ * // Creates call tracker.
55
+ * const tracker = new assert.CallTracker();
56
+ *
57
+ * function func() {}
58
+ *
59
+ * // Returns a function that wraps func() that must be called exact times
60
+ * // before tracker.verify().
61
+ * const callsfunc = tracker.calls(func);
62
+ * ```
63
+ *
64
+ * ```js
65
+ * const assert = require('assert');
66
+ *
67
+ * // Creates call tracker.
68
+ * const tracker = new assert.CallTracker();
69
+ *
70
+ * function func() {}
71
+ *
72
+ * // Returns a function that wraps func() that must be called exact times
73
+ * // before tracker.verify().
74
+ * const callsfunc = tracker.calls(func);
75
+ * ```
76
+ * @since v14.2.0, v12.19.0
77
+ * @return that wraps `fn`.
78
+ */
28
79
  calls(exact?: number): () => void;
29
80
  calls<Func extends (...args: any[]) => any>(fn?: Func, exact?: number): Func;
81
+ /**
82
+ * The arrays contains information about the expected and actual number of calls of
83
+ * the functions that have not been called the expected number of times.
84
+ *
85
+ * ```js
86
+ * import assert from 'assert';
87
+ *
88
+ * // Creates call tracker.
89
+ * const tracker = new assert.CallTracker();
90
+ *
91
+ * function func() {}
92
+ *
93
+ * function foo() {}
94
+ *
95
+ * // Returns a function that wraps func() that must be called exact times
96
+ * // before tracker.verify().
97
+ * const callsfunc = tracker.calls(func, 2);
98
+ *
99
+ * // Returns an array containing information on callsfunc()
100
+ * tracker.report();
101
+ * // [
102
+ * // {
103
+ * // message: 'Expected the func function to be executed 2 time(s) but was
104
+ * // executed 0 time(s).',
105
+ * // actual: 0,
106
+ * // expected: 2,
107
+ * // operator: 'func',
108
+ * // stack: stack trace
109
+ * // }
110
+ * // ]
111
+ * ```
112
+ *
113
+ * ```js
114
+ * const assert = require('assert');
115
+ *
116
+ * // Creates call tracker.
117
+ * const tracker = new assert.CallTracker();
118
+ *
119
+ * function func() {}
120
+ *
121
+ * function foo() {}
122
+ *
123
+ * // Returns a function that wraps func() that must be called exact times
124
+ * // before tracker.verify().
125
+ * const callsfunc = tracker.calls(func, 2);
126
+ *
127
+ * // Returns an array containing information on callsfunc()
128
+ * tracker.report();
129
+ * // [
130
+ * // {
131
+ * // message: 'Expected the func function to be executed 2 time(s) but was
132
+ * // executed 0 time(s).',
133
+ * // actual: 0,
134
+ * // expected: 2,
135
+ * // operator: 'func',
136
+ * // stack: stack trace
137
+ * // }
138
+ * // ]
139
+ * ```
140
+ * @since v14.2.0, v12.19.0
141
+ * @return of objects containing information about the wrapper functions returned by `calls`.
142
+ */
30
143
  report(): CallTrackerReportInformation[];
144
+ /**
145
+ * Iterates through the list of functions passed to `tracker.calls()` and will throw an error for functions that
146
+ * have not been called the expected number of times.
147
+ *
148
+ * ```js
149
+ * import assert from 'assert';
150
+ *
151
+ * // Creates call tracker.
152
+ * const tracker = new assert.CallTracker();
153
+ *
154
+ * function func() {}
155
+ *
156
+ * // Returns a function that wraps func() that must be called exact times
157
+ * // before tracker.verify().
158
+ * const callsfunc = tracker.calls(func, 2);
159
+ *
160
+ * callsfunc();
161
+ *
162
+ * // Will throw an error since callsfunc() was only called once.
163
+ * tracker.verify();
164
+ * ```
165
+ *
166
+ * ```js
167
+ * const assert = require('assert');
168
+ *
169
+ * // Creates call tracker.
170
+ * const tracker = new assert.CallTracker();
171
+ *
172
+ * function func() {}
173
+ *
174
+ * // Returns a function that wraps func() that must be called exact times
175
+ * // before tracker.verify().
176
+ * const callsfunc = tracker.calls(func, 2);
177
+ *
178
+ * callsfunc();
179
+ *
180
+ * // Will throw an error since callsfunc() was only called once.
181
+ * tracker.verify();
182
+ * ```
183
+ * @since v14.2.0, v12.19.0
184
+ */
31
185
  verify(): void;
32
186
  }
33
187
  interface CallTrackerReportInformation {
@@ -41,9 +195,42 @@ declare module 'assert' {
41
195
  /** A stack trace of the function. */
42
196
  stack: object;
43
197
  }
44
-
45
198
  type AssertPredicate = RegExp | (new () => object) | ((thrown: unknown) => boolean) | object | Error;
46
-
199
+ /**
200
+ * Throws an `AssertionError` with the provided error message or a default
201
+ * error message. If the `message` parameter is an instance of an `Error` then
202
+ * it will be thrown instead of the `AssertionError`.
203
+ *
204
+ * ```js
205
+ * import assert from 'assert/strict';
206
+ *
207
+ * assert.fail();
208
+ * // AssertionError [ERR_ASSERTION]: Failed
209
+ *
210
+ * assert.fail('boom');
211
+ * // AssertionError [ERR_ASSERTION]: boom
212
+ *
213
+ * assert.fail(new TypeError('need array'));
214
+ * // TypeError: need array
215
+ * ```
216
+ *
217
+ * ```js
218
+ * const assert = require('assert/strict');
219
+ *
220
+ * assert.fail();
221
+ * // AssertionError [ERR_ASSERTION]: Failed
222
+ *
223
+ * assert.fail('boom');
224
+ * // AssertionError [ERR_ASSERTION]: boom
225
+ *
226
+ * assert.fail(new TypeError('need array'));
227
+ * // TypeError: need array
228
+ * ```
229
+ *
230
+ * Using `assert.fail()` with more than two arguments is possible but deprecated.
231
+ * See below for further details.
232
+ * @since v0.1.21
233
+ */
47
234
  function fail(message?: string | Error): never;
48
235
  /** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
49
236
  function fail(
@@ -52,63 +239,1190 @@ declare module 'assert' {
52
239
  message?: string | Error,
53
240
  operator?: string,
54
241
  // tslint:disable-next-line:ban-types
55
- stackStartFn?: Function,
242
+ stackStartFn?: Function
56
243
  ): never;
244
+ /**
245
+ * Tests if `value` is truthy. It is equivalent to`assert.equal(!!value, true, message)`.
246
+ *
247
+ * If `value` is not truthy, an `AssertionError` is thrown with a `message`property set equal to the value of the `message` parameter. If the `message`parameter is `undefined`, a default
248
+ * error message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
249
+ * If no arguments are passed in at all `message` will be set to the string:`` 'No value argument passed to `assert.ok()`' ``.
250
+ *
251
+ * Be aware that in the `repl` the error message will be different to the one
252
+ * thrown in a file! See below for further details.
253
+ *
254
+ * ```js
255
+ * import assert from 'assert/strict';
256
+ *
257
+ * assert.ok(true);
258
+ * // OK
259
+ * assert.ok(1);
260
+ * // OK
261
+ *
262
+ * assert.ok();
263
+ * // AssertionError: No value argument passed to `assert.ok()`
264
+ *
265
+ * assert.ok(false, 'it\'s false');
266
+ * // AssertionError: it's false
267
+ *
268
+ * // In the repl:
269
+ * assert.ok(typeof 123 === 'string');
270
+ * // AssertionError: false == true
271
+ *
272
+ * // In a file (e.g. test.js):
273
+ * assert.ok(typeof 123 === 'string');
274
+ * // AssertionError: The expression evaluated to a falsy value:
275
+ * //
276
+ * // assert.ok(typeof 123 === 'string')
277
+ *
278
+ * assert.ok(false);
279
+ * // AssertionError: The expression evaluated to a falsy value:
280
+ * //
281
+ * // assert.ok(false)
282
+ *
283
+ * assert.ok(0);
284
+ * // AssertionError: The expression evaluated to a falsy value:
285
+ * //
286
+ * // assert.ok(0)
287
+ * ```
288
+ *
289
+ * ```js
290
+ * const assert = require('assert/strict');
291
+ *
292
+ * assert.ok(true);
293
+ * // OK
294
+ * assert.ok(1);
295
+ * // OK
296
+ *
297
+ * assert.ok();
298
+ * // AssertionError: No value argument passed to `assert.ok()`
299
+ *
300
+ * assert.ok(false, 'it\'s false');
301
+ * // AssertionError: it's false
302
+ *
303
+ * // In the repl:
304
+ * assert.ok(typeof 123 === 'string');
305
+ * // AssertionError: false == true
306
+ *
307
+ * // In a file (e.g. test.js):
308
+ * assert.ok(typeof 123 === 'string');
309
+ * // AssertionError: The expression evaluated to a falsy value:
310
+ * //
311
+ * // assert.ok(typeof 123 === 'string')
312
+ *
313
+ * assert.ok(false);
314
+ * // AssertionError: The expression evaluated to a falsy value:
315
+ * //
316
+ * // assert.ok(false)
317
+ *
318
+ * assert.ok(0);
319
+ * // AssertionError: The expression evaluated to a falsy value:
320
+ * //
321
+ * // assert.ok(0)
322
+ * ```
323
+ *
324
+ * ```js
325
+ * import assert from 'assert/strict';
326
+ *
327
+ * // Using `assert()` works the same:
328
+ * assert(0);
329
+ * // AssertionError: The expression evaluated to a falsy value:
330
+ * //
331
+ * // assert(0)
332
+ * ```
333
+ *
334
+ * ```js
335
+ * const assert = require('assert');
336
+ *
337
+ * // Using `assert()` works the same:
338
+ * assert(0);
339
+ * // AssertionError: The expression evaluated to a falsy value:
340
+ * //
341
+ * // assert(0)
342
+ * ```
343
+ * @since v0.1.21
344
+ */
57
345
  function ok(value: unknown, message?: string | Error): asserts value;
58
- /** @deprecated since v9.9.0 - use strictEqual() instead. */
346
+ /**
347
+ * **Strict assertion mode**
348
+ *
349
+ * An alias of {@link strictEqual}.
350
+ *
351
+ * **Legacy assertion mode**
352
+ *
353
+ * > Stability: 3 - Legacy: Use {@link strictEqual} instead.
354
+ *
355
+ * Tests shallow, coercive equality between the `actual` and `expected` parameters
356
+ * using the [Abstract Equality Comparison](https://tc39.github.io/ecma262/#sec-abstract-equality-comparison) ( `==` ). `NaN` is special handled
357
+ * and treated as being identical in case both sides are `NaN`.
358
+ *
359
+ * ```js
360
+ * import assert from 'assert';
361
+ *
362
+ * assert.equal(1, 1);
363
+ * // OK, 1 == 1
364
+ * assert.equal(1, '1');
365
+ * // OK, 1 == '1'
366
+ * assert.equal(NaN, NaN);
367
+ * // OK
368
+ *
369
+ * assert.equal(1, 2);
370
+ * // AssertionError: 1 == 2
371
+ * assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
372
+ * // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
373
+ * ```
374
+ *
375
+ * ```js
376
+ * const assert = require('assert');
377
+ *
378
+ * assert.equal(1, 1);
379
+ * // OK, 1 == 1
380
+ * assert.equal(1, '1');
381
+ * // OK, 1 == '1'
382
+ * assert.equal(NaN, NaN);
383
+ * // OK
384
+ *
385
+ * assert.equal(1, 2);
386
+ * // AssertionError: 1 == 2
387
+ * assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
388
+ * // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
389
+ * ```
390
+ *
391
+ * If the values are not equal, an `AssertionError` is thrown with a `message`property set equal to the value of the `message` parameter. If the `message`parameter is undefined, a default
392
+ * error message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
393
+ * @since v0.1.21
394
+ */
59
395
  function equal(actual: unknown, expected: unknown, message?: string | Error): void;
60
- /** @deprecated since v9.9.0 - use notStrictEqual() instead. */
396
+ /**
397
+ * **Strict assertion mode**
398
+ *
399
+ * An alias of {@link notStrictEqual}.
400
+ *
401
+ * **Legacy assertion mode**
402
+ *
403
+ * > Stability: 3 - Legacy: Use {@link notStrictEqual} instead.
404
+ *
405
+ * Tests shallow, coercive inequality with the [Abstract Equality Comparison](https://tc39.github.io/ecma262/#sec-abstract-equality-comparison)(`!=` ). `NaN` is special handled and treated as
406
+ * being identical in case both
407
+ * sides are `NaN`.
408
+ *
409
+ * ```js
410
+ * import assert from 'assert';
411
+ *
412
+ * assert.notEqual(1, 2);
413
+ * // OK
414
+ *
415
+ * assert.notEqual(1, 1);
416
+ * // AssertionError: 1 != 1
417
+ *
418
+ * assert.notEqual(1, '1');
419
+ * // AssertionError: 1 != '1'
420
+ * ```
421
+ *
422
+ * ```js
423
+ * const assert = require('assert');
424
+ *
425
+ * assert.notEqual(1, 2);
426
+ * // OK
427
+ *
428
+ * assert.notEqual(1, 1);
429
+ * // AssertionError: 1 != 1
430
+ *
431
+ * assert.notEqual(1, '1');
432
+ * // AssertionError: 1 != '1'
433
+ * ```
434
+ *
435
+ * If the values are equal, an `AssertionError` is thrown with a `message`property set equal to the value of the `message` parameter. If the `message`parameter is undefined, a default error
436
+ * message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
437
+ * @since v0.1.21
438
+ */
61
439
  function notEqual(actual: unknown, expected: unknown, message?: string | Error): void;
62
- /** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
440
+ /**
441
+ * **Strict assertion mode**
442
+ *
443
+ * An alias of {@link deepStrictEqual}.
444
+ *
445
+ * **Legacy assertion mode**
446
+ *
447
+ * > Stability: 3 - Legacy: Use {@link deepStrictEqual} instead.
448
+ *
449
+ * Tests for deep equality between the `actual` and `expected` parameters. Consider
450
+ * using {@link deepStrictEqual} instead. {@link deepEqual} can have
451
+ * surprising results.
452
+ *
453
+ * _Deep equality_ means that the enumerable "own" properties of child objects
454
+ * are also recursively evaluated by the following rules.
455
+ * @since v0.1.21
456
+ */
63
457
  function deepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
64
- /** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
458
+ /**
459
+ * **Strict assertion mode**
460
+ *
461
+ * An alias of {@link notDeepStrictEqual}.
462
+ *
463
+ * **Legacy assertion mode**
464
+ *
465
+ * > Stability: 3 - Legacy: Use {@link notDeepStrictEqual} instead.
466
+ *
467
+ * Tests for any deep inequality. Opposite of {@link deepEqual}.
468
+ *
469
+ * ```js
470
+ * import assert from 'assert';
471
+ *
472
+ * const obj1 = {
473
+ * a: {
474
+ * b: 1
475
+ * }
476
+ * };
477
+ * const obj2 = {
478
+ * a: {
479
+ * b: 2
480
+ * }
481
+ * };
482
+ * const obj3 = {
483
+ * a: {
484
+ * b: 1
485
+ * }
486
+ * };
487
+ * const obj4 = Object.create(obj1);
488
+ *
489
+ * assert.notDeepEqual(obj1, obj1);
490
+ * // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
491
+ *
492
+ * assert.notDeepEqual(obj1, obj2);
493
+ * // OK
494
+ *
495
+ * assert.notDeepEqual(obj1, obj3);
496
+ * // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
497
+ *
498
+ * assert.notDeepEqual(obj1, obj4);
499
+ * // OK
500
+ * ```
501
+ *
502
+ * ```js
503
+ * const assert = require('assert');
504
+ *
505
+ * const obj1 = {
506
+ * a: {
507
+ * b: 1
508
+ * }
509
+ * };
510
+ * const obj2 = {
511
+ * a: {
512
+ * b: 2
513
+ * }
514
+ * };
515
+ * const obj3 = {
516
+ * a: {
517
+ * b: 1
518
+ * }
519
+ * };
520
+ * const obj4 = Object.create(obj1);
521
+ *
522
+ * assert.notDeepEqual(obj1, obj1);
523
+ * // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
524
+ *
525
+ * assert.notDeepEqual(obj1, obj2);
526
+ * // OK
527
+ *
528
+ * assert.notDeepEqual(obj1, obj3);
529
+ * // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
530
+ *
531
+ * assert.notDeepEqual(obj1, obj4);
532
+ * // OK
533
+ * ```
534
+ *
535
+ * If the values are deeply equal, an `AssertionError` is thrown with a`message` property set equal to the value of the `message` parameter. If the`message` parameter is undefined, a default
536
+ * error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
537
+ * instead of the `AssertionError`.
538
+ * @since v0.1.21
539
+ */
65
540
  function notDeepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
541
+ /**
542
+ * Tests strict equality between the `actual` and `expected` parameters as
543
+ * determined by the [SameValue Comparison](https://tc39.github.io/ecma262/#sec-samevalue).
544
+ *
545
+ * ```js
546
+ * import assert from 'assert/strict';
547
+ *
548
+ * assert.strictEqual(1, 2);
549
+ * // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
550
+ * //
551
+ * // 1 !== 2
552
+ *
553
+ * assert.strictEqual(1, 1);
554
+ * // OK
555
+ *
556
+ * assert.strictEqual('Hello foobar', 'Hello World!');
557
+ * // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
558
+ * // + actual - expected
559
+ * //
560
+ * // + 'Hello foobar'
561
+ * // - 'Hello World!'
562
+ * // ^
563
+ *
564
+ * const apples = 1;
565
+ * const oranges = 2;
566
+ * assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);
567
+ * // AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2
568
+ *
569
+ * assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
570
+ * // TypeError: Inputs are not identical
571
+ * ```
572
+ *
573
+ * ```js
574
+ * const assert = require('assert/strict');
575
+ *
576
+ * assert.strictEqual(1, 2);
577
+ * // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
578
+ * //
579
+ * // 1 !== 2
580
+ *
581
+ * assert.strictEqual(1, 1);
582
+ * // OK
583
+ *
584
+ * assert.strictEqual('Hello foobar', 'Hello World!');
585
+ * // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
586
+ * // + actual - expected
587
+ * //
588
+ * // + 'Hello foobar'
589
+ * // - 'Hello World!'
590
+ * // ^
591
+ *
592
+ * const apples = 1;
593
+ * const oranges = 2;
594
+ * assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);
595
+ * // AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2
596
+ *
597
+ * assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
598
+ * // TypeError: Inputs are not identical
599
+ * ```
600
+ *
601
+ * If the values are not strictly equal, an `AssertionError` is thrown with a`message` property set equal to the value of the `message` parameter. If the`message` parameter is undefined, a
602
+ * default error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
603
+ * instead of the `AssertionError`.
604
+ * @since v0.1.21
605
+ */
66
606
  function strictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
607
+ /**
608
+ * Tests strict inequality between the `actual` and `expected` parameters as
609
+ * determined by the [SameValue Comparison](https://tc39.github.io/ecma262/#sec-samevalue).
610
+ *
611
+ * ```js
612
+ * import assert from 'assert/strict';
613
+ *
614
+ * assert.notStrictEqual(1, 2);
615
+ * // OK
616
+ *
617
+ * assert.notStrictEqual(1, 1);
618
+ * // AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
619
+ * //
620
+ * // 1
621
+ *
622
+ * assert.notStrictEqual(1, '1');
623
+ * // OK
624
+ * ```
625
+ *
626
+ * ```js
627
+ * const assert = require('assert/strict');
628
+ *
629
+ * assert.notStrictEqual(1, 2);
630
+ * // OK
631
+ *
632
+ * assert.notStrictEqual(1, 1);
633
+ * // AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
634
+ * //
635
+ * // 1
636
+ *
637
+ * assert.notStrictEqual(1, '1');
638
+ * // OK
639
+ * ```
640
+ *
641
+ * If the values are strictly equal, an `AssertionError` is thrown with a`message` property set equal to the value of the `message` parameter. If the`message` parameter is undefined, a
642
+ * default error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
643
+ * instead of the `AssertionError`.
644
+ * @since v0.1.21
645
+ */
67
646
  function notStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
647
+ /**
648
+ * Tests for deep equality between the `actual` and `expected` parameters.
649
+ * "Deep" equality means that the enumerable "own" properties of child objects
650
+ * are recursively evaluated also by the following rules.
651
+ * @since v1.2.0
652
+ */
68
653
  function deepStrictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
654
+ /**
655
+ * Tests for deep strict inequality. Opposite of {@link deepStrictEqual}.
656
+ *
657
+ * ```js
658
+ * import assert from 'assert/strict';
659
+ *
660
+ * assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
661
+ * // OK
662
+ * ```
663
+ *
664
+ * ```js
665
+ * const assert = require('assert/strict');
666
+ *
667
+ * assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
668
+ * // OK
669
+ * ```
670
+ *
671
+ * If the values are deeply and strictly equal, an `AssertionError` is thrown
672
+ * with a `message` property set equal to the value of the `message` parameter. If
673
+ * the `message` parameter is undefined, a default error message is assigned. If
674
+ * the `message` parameter is an instance of an `Error` then it will be thrown
675
+ * instead of the `AssertionError`.
676
+ * @since v1.2.0
677
+ */
69
678
  function notDeepStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
70
-
679
+ /**
680
+ * Expects the function `fn` to throw an error.
681
+ *
682
+ * If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
683
+ * [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
684
+ * a validation object where each property will be tested for strict deep equality,
685
+ * or an instance of error where each property will be tested for strict deep
686
+ * equality including the non-enumerable `message` and `name` properties. When
687
+ * using an object, it is also possible to use a regular expression, when
688
+ * validating against a string property. See below for examples.
689
+ *
690
+ * If specified, `message` will be appended to the message provided by the`AssertionError` if the `fn` call fails to throw or in case the error validation
691
+ * fails.
692
+ *
693
+ * Custom validation object/error instance:
694
+ *
695
+ * ```js
696
+ * import assert from 'assert/strict';
697
+ *
698
+ * const err = new TypeError('Wrong value');
699
+ * err.code = 404;
700
+ * err.foo = 'bar';
701
+ * err.info = {
702
+ * nested: true,
703
+ * baz: 'text'
704
+ * };
705
+ * err.reg = /abc/i;
706
+ *
707
+ * assert.throws(
708
+ * () => {
709
+ * throw err;
710
+ * },
711
+ * {
712
+ * name: 'TypeError',
713
+ * message: 'Wrong value',
714
+ * info: {
715
+ * nested: true,
716
+ * baz: 'text'
717
+ * }
718
+ * // Only properties on the validation object will be tested for.
719
+ * // Using nested objects requires all properties to be present. Otherwise
720
+ * // the validation is going to fail.
721
+ * }
722
+ * );
723
+ *
724
+ * // Using regular expressions to validate error properties:
725
+ * throws(
726
+ * () => {
727
+ * throw err;
728
+ * },
729
+ * {
730
+ * // The `name` and `message` properties are strings and using regular
731
+ * // expressions on those will match against the string. If they fail, an
732
+ * // error is thrown.
733
+ * name: /^TypeError$/,
734
+ * message: /Wrong/,
735
+ * foo: 'bar',
736
+ * info: {
737
+ * nested: true,
738
+ * // It is not possible to use regular expressions for nested properties!
739
+ * baz: 'text'
740
+ * },
741
+ * // The `reg` property contains a regular expression and only if the
742
+ * // validation object contains an identical regular expression, it is going
743
+ * // to pass.
744
+ * reg: /abc/i
745
+ * }
746
+ * );
747
+ *
748
+ * // Fails due to the different `message` and `name` properties:
749
+ * throws(
750
+ * () => {
751
+ * const otherErr = new Error('Not found');
752
+ * // Copy all enumerable properties from `err` to `otherErr`.
753
+ * for (const [key, value] of Object.entries(err)) {
754
+ * otherErr[key] = value;
755
+ * }
756
+ * throw otherErr;
757
+ * },
758
+ * // The error's `message` and `name` properties will also be checked when using
759
+ * // an error as validation object.
760
+ * err
761
+ * );
762
+ * ```
763
+ *
764
+ * ```js
765
+ * const assert = require('assert/strict');
766
+ *
767
+ * const err = new TypeError('Wrong value');
768
+ * err.code = 404;
769
+ * err.foo = 'bar';
770
+ * err.info = {
771
+ * nested: true,
772
+ * baz: 'text'
773
+ * };
774
+ * err.reg = /abc/i;
775
+ *
776
+ * assert.throws(
777
+ * () => {
778
+ * throw err;
779
+ * },
780
+ * {
781
+ * name: 'TypeError',
782
+ * message: 'Wrong value',
783
+ * info: {
784
+ * nested: true,
785
+ * baz: 'text'
786
+ * }
787
+ * // Only properties on the validation object will be tested for.
788
+ * // Using nested objects requires all properties to be present. Otherwise
789
+ * // the validation is going to fail.
790
+ * }
791
+ * );
792
+ *
793
+ * // Using regular expressions to validate error properties:
794
+ * throws(
795
+ * () => {
796
+ * throw err;
797
+ * },
798
+ * {
799
+ * // The `name` and `message` properties are strings and using regular
800
+ * // expressions on those will match against the string. If they fail, an
801
+ * // error is thrown.
802
+ * name: /^TypeError$/,
803
+ * message: /Wrong/,
804
+ * foo: 'bar',
805
+ * info: {
806
+ * nested: true,
807
+ * // It is not possible to use regular expressions for nested properties!
808
+ * baz: 'text'
809
+ * },
810
+ * // The `reg` property contains a regular expression and only if the
811
+ * // validation object contains an identical regular expression, it is going
812
+ * // to pass.
813
+ * reg: /abc/i
814
+ * }
815
+ * );
816
+ *
817
+ * // Fails due to the different `message` and `name` properties:
818
+ * throws(
819
+ * () => {
820
+ * const otherErr = new Error('Not found');
821
+ * // Copy all enumerable properties from `err` to `otherErr`.
822
+ * for (const [key, value] of Object.entries(err)) {
823
+ * otherErr[key] = value;
824
+ * }
825
+ * throw otherErr;
826
+ * },
827
+ * // The error's `message` and `name` properties will also be checked when using
828
+ * // an error as validation object.
829
+ * err
830
+ * );
831
+ * ```
832
+ *
833
+ * Validate instanceof using constructor:
834
+ *
835
+ * ```js
836
+ * import assert from 'assert/strict';
837
+ *
838
+ * assert.throws(
839
+ * () => {
840
+ * throw new Error('Wrong value');
841
+ * },
842
+ * Error
843
+ * );
844
+ * ```
845
+ *
846
+ * ```js
847
+ * const assert = require('assert/strict');
848
+ *
849
+ * assert.throws(
850
+ * () => {
851
+ * throw new Error('Wrong value');
852
+ * },
853
+ * Error
854
+ * );
855
+ * ```
856
+ *
857
+ * Validate error message using [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions):
858
+ *
859
+ * Using a regular expression runs `.toString` on the error object, and will
860
+ * therefore also include the error name.
861
+ *
862
+ * ```js
863
+ * import assert from 'assert/strict';
864
+ *
865
+ * assert.throws(
866
+ * () => {
867
+ * throw new Error('Wrong value');
868
+ * },
869
+ * /^Error: Wrong value$/
870
+ * );
871
+ * ```
872
+ *
873
+ * ```js
874
+ * const assert = require('assert/strict');
875
+ *
876
+ * assert.throws(
877
+ * () => {
878
+ * throw new Error('Wrong value');
879
+ * },
880
+ * /^Error: Wrong value$/
881
+ * );
882
+ * ```
883
+ *
884
+ * Custom error validation:
885
+ *
886
+ * The function must return `true` to indicate all internal validations passed.
887
+ * It will otherwise fail with an `AssertionError`.
888
+ *
889
+ * ```js
890
+ * import assert from 'assert/strict';
891
+ *
892
+ * assert.throws(
893
+ * () => {
894
+ * throw new Error('Wrong value');
895
+ * },
896
+ * (err) => {
897
+ * assert(err instanceof Error);
898
+ * assert(/value/.test(err));
899
+ * // Avoid returning anything from validation functions besides `true`.
900
+ * // Otherwise, it's not clear what part of the validation failed. Instead,
901
+ * // throw an error about the specific validation that failed (as done in this
902
+ * // example) and add as much helpful debugging information to that error as
903
+ * // possible.
904
+ * return true;
905
+ * },
906
+ * 'unexpected error'
907
+ * );
908
+ * ```
909
+ *
910
+ * ```js
911
+ * const assert = require('assert/strict');
912
+ *
913
+ * assert.throws(
914
+ * () => {
915
+ * throw new Error('Wrong value');
916
+ * },
917
+ * (err) => {
918
+ * assert(err instanceof Error);
919
+ * assert(/value/.test(err));
920
+ * // Avoid returning anything from validation functions besides `true`.
921
+ * // Otherwise, it's not clear what part of the validation failed. Instead,
922
+ * // throw an error about the specific validation that failed (as done in this
923
+ * // example) and add as much helpful debugging information to that error as
924
+ * // possible.
925
+ * return true;
926
+ * },
927
+ * 'unexpected error'
928
+ * );
929
+ * ```
930
+ *
931
+ * `error` cannot be a string. If a string is provided as the second
932
+ * argument, then `error` is assumed to be omitted and the string will be used for`message` instead. This can lead to easy-to-miss mistakes. Using the same
933
+ * message as the thrown error message is going to result in an`ERR_AMBIGUOUS_ARGUMENT` error. Please read the example below carefully if using
934
+ * a string as the second argument gets considered:
935
+ *
936
+ * ```js
937
+ * import assert from 'assert/strict';
938
+ *
939
+ * function throwingFirst() {
940
+ * throw new Error('First');
941
+ * }
942
+ *
943
+ * function throwingSecond() {
944
+ * throw new Error('Second');
945
+ * }
946
+ *
947
+ * function notThrowing() {}
948
+ *
949
+ * // The second argument is a string and the input function threw an Error.
950
+ * // The first case will not throw as it does not match for the error message
951
+ * // thrown by the input function!
952
+ * assert.throws(throwingFirst, 'Second');
953
+ * // In the next example the message has no benefit over the message from the
954
+ * // error and since it is not clear if the user intended to actually match
955
+ * // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.
956
+ * assert.throws(throwingSecond, 'Second');
957
+ * // TypeError [ERR_AMBIGUOUS_ARGUMENT]
958
+ *
959
+ * // The string is only used (as message) in case the function does not throw:
960
+ * assert.throws(notThrowing, 'Second');
961
+ * // AssertionError [ERR_ASSERTION]: Missing expected exception: Second
962
+ *
963
+ * // If it was intended to match for the error message do this instead:
964
+ * // It does not throw because the error messages match.
965
+ * assert.throws(throwingSecond, /Second$/);
966
+ *
967
+ * // If the error message does not match, an AssertionError is thrown.
968
+ * assert.throws(throwingFirst, /Second$/);
969
+ * // AssertionError [ERR_ASSERTION]
970
+ * ```
971
+ *
972
+ * ```js
973
+ * const assert = require('assert/strict');
974
+ *
975
+ * function throwingFirst() {
976
+ * throw new Error('First');
977
+ * }
978
+ *
979
+ * function throwingSecond() {
980
+ * throw new Error('Second');
981
+ * }
982
+ *
983
+ * function notThrowing() {}
984
+ *
985
+ * // The second argument is a string and the input function threw an Error.
986
+ * // The first case will not throw as it does not match for the error message
987
+ * // thrown by the input function!
988
+ * assert.throws(throwingFirst, 'Second');
989
+ * // In the next example the message has no benefit over the message from the
990
+ * // error and since it is not clear if the user intended to actually match
991
+ * // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.
992
+ * assert.throws(throwingSecond, 'Second');
993
+ * // TypeError [ERR_AMBIGUOUS_ARGUMENT]
994
+ *
995
+ * // The string is only used (as message) in case the function does not throw:
996
+ * assert.throws(notThrowing, 'Second');
997
+ * // AssertionError [ERR_ASSERTION]: Missing expected exception: Second
998
+ *
999
+ * // If it was intended to match for the error message do this instead:
1000
+ * // It does not throw because the error messages match.
1001
+ * assert.throws(throwingSecond, /Second$/);
1002
+ *
1003
+ * // If the error message does not match, an AssertionError is thrown.
1004
+ * assert.throws(throwingFirst, /Second$/);
1005
+ * // AssertionError [ERR_ASSERTION]
1006
+ * ```
1007
+ *
1008
+ * Due to the confusing error-prone notation, avoid a string as the second
1009
+ * argument.
1010
+ * @since v0.1.21
1011
+ */
71
1012
  function throws(block: () => unknown, message?: string | Error): void;
72
1013
  function throws(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
1014
+ /**
1015
+ * Asserts that the function `fn` does not throw an error.
1016
+ *
1017
+ * Using `assert.doesNotThrow()` is actually not useful because there
1018
+ * is no benefit in catching an error and then rethrowing it. Instead, consider
1019
+ * adding a comment next to the specific code path that should not throw and keep
1020
+ * error messages as expressive as possible.
1021
+ *
1022
+ * When `assert.doesNotThrow()` is called, it will immediately call the `fn`function.
1023
+ *
1024
+ * If an error is thrown and it is the same type as that specified by the `error`parameter, then an `AssertionError` is thrown. If the error is of a
1025
+ * different type, or if the `error` parameter is undefined, the error is
1026
+ * propagated back to the caller.
1027
+ *
1028
+ * If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
1029
+ * [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) or a validation
1030
+ * function. See {@link throws} for more details.
1031
+ *
1032
+ * The following, for instance, will throw the `TypeError` because there is no
1033
+ * matching error type in the assertion:
1034
+ *
1035
+ * ```js
1036
+ * import assert from 'assert/strict';
1037
+ *
1038
+ * assert.doesNotThrow(
1039
+ * () => {
1040
+ * throw new TypeError('Wrong value');
1041
+ * },
1042
+ * SyntaxError
1043
+ * );
1044
+ * ```
1045
+ *
1046
+ * ```js
1047
+ * const assert = require('assert/strict');
1048
+ *
1049
+ * assert.doesNotThrow(
1050
+ * () => {
1051
+ * throw new TypeError('Wrong value');
1052
+ * },
1053
+ * SyntaxError
1054
+ * );
1055
+ * ```
1056
+ *
1057
+ * However, the following will result in an `AssertionError` with the message
1058
+ * 'Got unwanted exception...':
1059
+ *
1060
+ * ```js
1061
+ * import assert from 'assert/strict';
1062
+ *
1063
+ * assert.doesNotThrow(
1064
+ * () => {
1065
+ * throw new TypeError('Wrong value');
1066
+ * },
1067
+ * TypeError
1068
+ * );
1069
+ * ```
1070
+ *
1071
+ * ```js
1072
+ * const assert = require('assert/strict');
1073
+ *
1074
+ * assert.doesNotThrow(
1075
+ * () => {
1076
+ * throw new TypeError('Wrong value');
1077
+ * },
1078
+ * TypeError
1079
+ * );
1080
+ * ```
1081
+ *
1082
+ * If an `AssertionError` is thrown and a value is provided for the `message`parameter, the value of `message` will be appended to the `AssertionError` message:
1083
+ *
1084
+ * ```js
1085
+ * import assert from 'assert/strict';
1086
+ *
1087
+ * assert.doesNotThrow(
1088
+ * () => {
1089
+ * throw new TypeError('Wrong value');
1090
+ * },
1091
+ * /Wrong value/,
1092
+ * 'Whoops'
1093
+ * );
1094
+ * // Throws: AssertionError: Got unwanted exception: Whoops
1095
+ * ```
1096
+ *
1097
+ * ```js
1098
+ * const assert = require('assert/strict');
1099
+ *
1100
+ * assert.doesNotThrow(
1101
+ * () => {
1102
+ * throw new TypeError('Wrong value');
1103
+ * },
1104
+ * /Wrong value/,
1105
+ * 'Whoops'
1106
+ * );
1107
+ * // Throws: AssertionError: Got unwanted exception: Whoops
1108
+ * ```
1109
+ * @since v0.1.21
1110
+ */
73
1111
  function doesNotThrow(block: () => unknown, message?: string | Error): void;
74
1112
  function doesNotThrow(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
75
-
1113
+ /**
1114
+ * Throws `value` if `value` is not `undefined` or `null`. This is useful when
1115
+ * testing the `error` argument in callbacks. The stack trace contains all frames
1116
+ * from the error passed to `ifError()` including the potential new frames for`ifError()` itself.
1117
+ *
1118
+ * ```js
1119
+ * import assert from 'assert/strict';
1120
+ *
1121
+ * assert.ifError(null);
1122
+ * // OK
1123
+ * assert.ifError(0);
1124
+ * // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
1125
+ * assert.ifError('error');
1126
+ * // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
1127
+ * assert.ifError(new Error());
1128
+ * // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
1129
+ *
1130
+ * // Create some random error frames.
1131
+ * let err;
1132
+ * (function errorFrame() {
1133
+ * err = new Error('test error');
1134
+ * })();
1135
+ *
1136
+ * (function ifErrorFrame() {
1137
+ * assert.ifError(err);
1138
+ * })();
1139
+ * // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
1140
+ * // at ifErrorFrame
1141
+ * // at errorFrame
1142
+ * ```
1143
+ *
1144
+ * ```js
1145
+ * const assert = require('assert/strict');
1146
+ *
1147
+ * assert.ifError(null);
1148
+ * // OK
1149
+ * assert.ifError(0);
1150
+ * // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
1151
+ * assert.ifError('error');
1152
+ * // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
1153
+ * assert.ifError(new Error());
1154
+ * // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
1155
+ *
1156
+ * // Create some random error frames.
1157
+ * let err;
1158
+ * (function errorFrame() {
1159
+ * err = new Error('test error');
1160
+ * })();
1161
+ *
1162
+ * (function ifErrorFrame() {
1163
+ * assert.ifError(err);
1164
+ * })();
1165
+ * // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
1166
+ * // at ifErrorFrame
1167
+ * // at errorFrame
1168
+ * ```
1169
+ * @since v0.1.97
1170
+ */
76
1171
  function ifError(value: unknown): asserts value is null | undefined;
77
-
1172
+ /**
1173
+ * Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
1174
+ * calls the function and awaits the returned promise to complete. It will then
1175
+ * check that the promise is rejected.
1176
+ *
1177
+ * If `asyncFn` is a function and it throws an error synchronously,`assert.rejects()` will return a rejected `Promise` with that error. If the
1178
+ * function does not return a promise, `assert.rejects()` will return a rejected`Promise` with an `ERR_INVALID_RETURN_VALUE` error. In both cases the error
1179
+ * handler is skipped.
1180
+ *
1181
+ * Besides the async nature to await the completion behaves identically to {@link throws}.
1182
+ *
1183
+ * If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
1184
+ * [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
1185
+ * an object where each property will be tested for, or an instance of error where
1186
+ * each property will be tested for including the non-enumerable `message` and`name` properties.
1187
+ *
1188
+ * If specified, `message` will be the message provided by the `AssertionError` if the `asyncFn` fails to reject.
1189
+ *
1190
+ * ```js
1191
+ * import assert from 'assert/strict';
1192
+ *
1193
+ * await assert.rejects(
1194
+ * async () => {
1195
+ * throw new TypeError('Wrong value');
1196
+ * },
1197
+ * {
1198
+ * name: 'TypeError',
1199
+ * message: 'Wrong value'
1200
+ * }
1201
+ * );
1202
+ * ```
1203
+ *
1204
+ * ```js
1205
+ * const assert = require('assert/strict');
1206
+ *
1207
+ * (async () => {
1208
+ * await assert.rejects(
1209
+ * async () => {
1210
+ * throw new TypeError('Wrong value');
1211
+ * },
1212
+ * {
1213
+ * name: 'TypeError',
1214
+ * message: 'Wrong value'
1215
+ * }
1216
+ * );
1217
+ * })();
1218
+ * ```
1219
+ *
1220
+ * ```js
1221
+ * import assert from 'assert/strict';
1222
+ *
1223
+ * await assert.rejects(
1224
+ * async () => {
1225
+ * throw new TypeError('Wrong value');
1226
+ * },
1227
+ * (err) => {
1228
+ * assert.strictEqual(err.name, 'TypeError');
1229
+ * assert.strictEqual(err.message, 'Wrong value');
1230
+ * return true;
1231
+ * }
1232
+ * );
1233
+ * ```
1234
+ *
1235
+ * ```js
1236
+ * const assert = require('assert/strict');
1237
+ *
1238
+ * (async () => {
1239
+ * await assert.rejects(
1240
+ * async () => {
1241
+ * throw new TypeError('Wrong value');
1242
+ * },
1243
+ * (err) => {
1244
+ * assert.strictEqual(err.name, 'TypeError');
1245
+ * assert.strictEqual(err.message, 'Wrong value');
1246
+ * return true;
1247
+ * }
1248
+ * );
1249
+ * })();
1250
+ * ```
1251
+ *
1252
+ * ```js
1253
+ * import assert from 'assert/strict';
1254
+ *
1255
+ * assert.rejects(
1256
+ * Promise.reject(new Error('Wrong value')),
1257
+ * Error
1258
+ * ).then(() => {
1259
+ * // ...
1260
+ * });
1261
+ * ```
1262
+ *
1263
+ * ```js
1264
+ * const assert = require('assert/strict');
1265
+ *
1266
+ * assert.rejects(
1267
+ * Promise.reject(new Error('Wrong value')),
1268
+ * Error
1269
+ * ).then(() => {
1270
+ * // ...
1271
+ * });
1272
+ * ```
1273
+ *
1274
+ * `error` cannot be a string. If a string is provided as the second
1275
+ * argument, then `error` is assumed to be omitted and the string will be used for`message` instead. This can lead to easy-to-miss mistakes. Please read the
1276
+ * example in {@link throws} carefully if using a string as the second
1277
+ * argument gets considered.
1278
+ * @since v10.0.0
1279
+ */
78
1280
  function rejects(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
79
- function rejects(
80
- block: (() => Promise<unknown>) | Promise<unknown>,
81
- error: AssertPredicate,
82
- message?: string | Error,
83
- ): Promise<void>;
1281
+ function rejects(block: (() => Promise<unknown>) | Promise<unknown>, error: AssertPredicate, message?: string | Error): Promise<void>;
1282
+ /**
1283
+ * Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
1284
+ * calls the function and awaits the returned promise to complete. It will then
1285
+ * check that the promise is not rejected.
1286
+ *
1287
+ * If `asyncFn` is a function and it throws an error synchronously,`assert.doesNotReject()` will return a rejected `Promise` with that error. If
1288
+ * the function does not return a promise, `assert.doesNotReject()` will return a
1289
+ * rejected `Promise` with an `ERR_INVALID_RETURN_VALUE` error. In both cases
1290
+ * the error handler is skipped.
1291
+ *
1292
+ * Using `assert.doesNotReject()` is actually not useful because there is little
1293
+ * benefit in catching a rejection and then rejecting it again. Instead, consider
1294
+ * adding a comment next to the specific code path that should not reject and keep
1295
+ * error messages as expressive as possible.
1296
+ *
1297
+ * If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
1298
+ * [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) or a validation
1299
+ * function. See {@link throws} for more details.
1300
+ *
1301
+ * Besides the async nature to await the completion behaves identically to {@link doesNotThrow}.
1302
+ *
1303
+ * ```js
1304
+ * import assert from 'assert/strict';
1305
+ *
1306
+ * await assert.doesNotReject(
1307
+ * async () => {
1308
+ * throw new TypeError('Wrong value');
1309
+ * },
1310
+ * SyntaxError
1311
+ * );
1312
+ * ```
1313
+ *
1314
+ * ```js
1315
+ * const assert = require('assert/strict');
1316
+ *
1317
+ * (async () => {
1318
+ * await assert.doesNotReject(
1319
+ * async () => {
1320
+ * throw new TypeError('Wrong value');
1321
+ * },
1322
+ * SyntaxError
1323
+ * );
1324
+ * })();
1325
+ * ```
1326
+ *
1327
+ * ```js
1328
+ * import assert from 'assert/strict';
1329
+ *
1330
+ * assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
1331
+ * .then(() => {
1332
+ * // ...
1333
+ * });
1334
+ * ```
1335
+ *
1336
+ * ```js
1337
+ * const assert = require('assert/strict');
1338
+ *
1339
+ * assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
1340
+ * .then(() => {
1341
+ * // ...
1342
+ * });
1343
+ * ```
1344
+ * @since v10.0.0
1345
+ */
84
1346
  function doesNotReject(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
85
- function doesNotReject(
86
- block: (() => Promise<unknown>) | Promise<unknown>,
87
- error: AssertPredicate,
88
- message?: string | Error,
89
- ): Promise<void>;
90
-
1347
+ function doesNotReject(block: (() => Promise<unknown>) | Promise<unknown>, error: AssertPredicate, message?: string | Error): Promise<void>;
1348
+ /**
1349
+ * Expects the `string` input to match the regular expression.
1350
+ *
1351
+ * ```js
1352
+ * import assert from 'assert/strict';
1353
+ *
1354
+ * assert.match('I will fail', /pass/);
1355
+ * // AssertionError [ERR_ASSERTION]: The input did not match the regular ...
1356
+ *
1357
+ * assert.match(123, /pass/);
1358
+ * // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
1359
+ *
1360
+ * assert.match('I will pass', /pass/);
1361
+ * // OK
1362
+ * ```
1363
+ *
1364
+ * ```js
1365
+ * const assert = require('assert/strict');
1366
+ *
1367
+ * assert.match('I will fail', /pass/);
1368
+ * // AssertionError [ERR_ASSERTION]: The input did not match the regular ...
1369
+ *
1370
+ * assert.match(123, /pass/);
1371
+ * // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
1372
+ *
1373
+ * assert.match('I will pass', /pass/);
1374
+ * // OK
1375
+ * ```
1376
+ *
1377
+ * If the values do not match, or if the `string` argument is of another type than`string`, an `AssertionError` is thrown with a `message` property set equal
1378
+ * to the value of the `message` parameter. If the `message` parameter is
1379
+ * undefined, a default error message is assigned. If the `message` parameter is an
1380
+ * instance of an `Error` then it will be thrown instead of the `AssertionError`.
1381
+ * @since v13.6.0, v12.16.0
1382
+ */
91
1383
  function match(value: string, regExp: RegExp, message?: string | Error): void;
1384
+ /**
1385
+ * Expects the `string` input not to match the regular expression.
1386
+ *
1387
+ * ```js
1388
+ * import assert from 'assert/strict';
1389
+ *
1390
+ * assert.doesNotMatch('I will fail', /fail/);
1391
+ * // AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
1392
+ *
1393
+ * assert.doesNotMatch(123, /pass/);
1394
+ * // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
1395
+ *
1396
+ * assert.doesNotMatch('I will pass', /different/);
1397
+ * // OK
1398
+ * ```
1399
+ *
1400
+ * ```js
1401
+ * const assert = require('assert/strict');
1402
+ *
1403
+ * assert.doesNotMatch('I will fail', /fail/);
1404
+ * // AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
1405
+ *
1406
+ * assert.doesNotMatch(123, /pass/);
1407
+ * // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
1408
+ *
1409
+ * assert.doesNotMatch('I will pass', /different/);
1410
+ * // OK
1411
+ * ```
1412
+ *
1413
+ * If the values do match, or if the `string` argument is of another type than`string`, an `AssertionError` is thrown with a `message` property set equal
1414
+ * to the value of the `message` parameter. If the `message` parameter is
1415
+ * undefined, a default error message is assigned. If the `message` parameter is an
1416
+ * instance of an `Error` then it will be thrown instead of the `AssertionError`.
1417
+ * @since v13.6.0, v12.16.0
1418
+ */
92
1419
  function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
93
-
94
- const strict: Omit<
95
- typeof assert,
96
- | 'equal'
97
- | 'notEqual'
98
- | 'deepEqual'
99
- | 'notDeepEqual'
100
- | 'ok'
101
- | 'strictEqual'
102
- | 'deepStrictEqual'
103
- | 'ifError'
104
- | 'strict'
105
- > & {
1420
+ const strict: Omit<typeof assert, 'equal' | 'notEqual' | 'deepEqual' | 'notDeepEqual' | 'ok' | 'strictEqual' | 'deepStrictEqual' | 'ifError' | 'strict'> & {
106
1421
  (value: unknown, message?: string | Error): asserts value;
107
1422
  equal: typeof strictEqual;
108
1423
  notEqual: typeof notStrictEqual;
109
1424
  deepEqual: typeof deepStrictEqual;
110
1425
  notDeepEqual: typeof notDeepStrictEqual;
111
-
112
1426
  // Mapped types and assertion functions are incompatible?
113
1427
  // TS2775: Assertions require every name in the call target
114
1428
  // to be declared with an explicit type annotation.
@@ -119,10 +1433,8 @@ declare module 'assert' {
119
1433
  strict: typeof strict;
120
1434
  };
121
1435
  }
122
-
123
1436
  export = assert;
124
1437
  }
125
-
126
1438
  declare module 'node:assert' {
127
1439
  import assert = require('assert');
128
1440
  export = assert;