@types/node 16.4.13 → 16.6.2
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/README.md +1 -1
- node/assert.d.ts +1 -531
- node/async_hooks.d.ts +16 -16
- node/base.d.ts +1 -1
- node/buffer.d.ts +143 -5
- node/child_process.d.ts +1 -1
- node/cluster.d.ts +13 -7
- node/console.d.ts +1 -1
- node/crypto.d.ts +63 -874
- node/dgram.d.ts +17 -8
- node/diagnostics_channel.d.ts +24 -7
- node/dns.d.ts +1 -1
- node/domain.d.ts +2 -2
- node/events.d.ts +1 -1
- node/fs/promises.d.ts +12 -5
- node/fs.d.ts +12 -16
- node/globals.d.ts +24 -13
- node/http.d.ts +63 -9
- node/http2.d.ts +1 -1
- node/https.d.ts +1 -1
- node/index.d.ts +1 -1
- node/inspector.d.ts +4 -5
- node/net.d.ts +1 -1
- node/os.d.ts +1 -1
- node/package.json +2 -2
- node/path.d.ts +1 -1
- node/perf_hooks.d.ts +1 -1
- node/process.d.ts +110 -35
- node/punycode.d.ts +2 -3
- node/querystring.d.ts +1 -1
- node/readline.d.ts +1 -1
- node/repl.d.ts +1 -1
- node/stream/web.d.ts +7 -0
- node/stream.d.ts +1 -1
- node/string_decoder.d.ts +1 -1
- node/timers/promises.d.ts +0 -45
- node/timers.d.ts +1 -1
- node/tls.d.ts +2 -2
- node/trace_events.d.ts +1 -1
- node/ts3.6/base.d.ts +2 -1
- node/tty.d.ts +4 -4
- node/url.d.ts +1 -75
- node/util.d.ts +1 -1
- node/v8.d.ts +1 -1
- node/vm.d.ts +2 -2
- node/wasi.d.ts +4 -24
- node/worker_threads.d.ts +1 -1
- node/zlib.d.ts +1 -1
node/assert.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The `assert` module provides a set of assertion functions for verifying
|
|
3
3
|
* invariants.
|
|
4
|
-
* @see [source](https://github.com/nodejs/node/blob/v16.
|
|
4
|
+
* @see [source](https://github.com/nodejs/node/blob/v16.6.0/lib/assert.js)
|
|
5
5
|
*/
|
|
6
6
|
declare module 'assert' {
|
|
7
7
|
/**
|
|
@@ -58,19 +58,6 @@ declare module 'assert' {
|
|
|
58
58
|
* // before tracker.verify().
|
|
59
59
|
* const callsfunc = tracker.calls(func);
|
|
60
60
|
* ```
|
|
61
|
-
*
|
|
62
|
-
* ```js
|
|
63
|
-
* const assert = require('assert');
|
|
64
|
-
*
|
|
65
|
-
* // Creates call tracker.
|
|
66
|
-
* const tracker = new assert.CallTracker();
|
|
67
|
-
*
|
|
68
|
-
* function func() {}
|
|
69
|
-
*
|
|
70
|
-
* // Returns a function that wraps func() that must be called exact times
|
|
71
|
-
* // before tracker.verify().
|
|
72
|
-
* const callsfunc = tracker.calls(func);
|
|
73
|
-
* ```
|
|
74
61
|
* @since v14.2.0, v12.19.0
|
|
75
62
|
* @param [fn='A no-op function']
|
|
76
63
|
* @param [exact=1]
|
|
@@ -109,34 +96,6 @@ declare module 'assert' {
|
|
|
109
96
|
* // }
|
|
110
97
|
* // ]
|
|
111
98
|
* ```
|
|
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
99
|
* @since v14.2.0, v12.19.0
|
|
141
100
|
* @return of objects containing information about the wrapper functions returned by `calls`.
|
|
142
101
|
*/
|
|
@@ -162,24 +121,6 @@ declare module 'assert' {
|
|
|
162
121
|
* // Will throw an error since callsfunc() was only called once.
|
|
163
122
|
* tracker.verify();
|
|
164
123
|
* ```
|
|
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
124
|
* @since v14.2.0, v12.19.0
|
|
184
125
|
*/
|
|
185
126
|
verify(): void;
|
|
@@ -214,19 +155,6 @@ declare module 'assert' {
|
|
|
214
155
|
* // TypeError: need array
|
|
215
156
|
* ```
|
|
216
157
|
*
|
|
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
158
|
* Using `assert.fail()` with more than two arguments is possible but deprecated.
|
|
231
159
|
* See below for further details.
|
|
232
160
|
* @since v0.1.21
|
|
@@ -288,41 +216,6 @@ declare module 'assert' {
|
|
|
288
216
|
* ```
|
|
289
217
|
*
|
|
290
218
|
* ```js
|
|
291
|
-
* const assert = require('assert/strict');
|
|
292
|
-
*
|
|
293
|
-
* assert.ok(true);
|
|
294
|
-
* // OK
|
|
295
|
-
* assert.ok(1);
|
|
296
|
-
* // OK
|
|
297
|
-
*
|
|
298
|
-
* assert.ok();
|
|
299
|
-
* // AssertionError: No value argument passed to `assert.ok()`
|
|
300
|
-
*
|
|
301
|
-
* assert.ok(false, 'it\'s false');
|
|
302
|
-
* // AssertionError: it's false
|
|
303
|
-
*
|
|
304
|
-
* // In the repl:
|
|
305
|
-
* assert.ok(typeof 123 === 'string');
|
|
306
|
-
* // AssertionError: false == true
|
|
307
|
-
*
|
|
308
|
-
* // In a file (e.g. test.js):
|
|
309
|
-
* assert.ok(typeof 123 === 'string');
|
|
310
|
-
* // AssertionError: The expression evaluated to a falsy value:
|
|
311
|
-
* //
|
|
312
|
-
* // assert.ok(typeof 123 === 'string')
|
|
313
|
-
*
|
|
314
|
-
* assert.ok(false);
|
|
315
|
-
* // AssertionError: The expression evaluated to a falsy value:
|
|
316
|
-
* //
|
|
317
|
-
* // assert.ok(false)
|
|
318
|
-
*
|
|
319
|
-
* assert.ok(0);
|
|
320
|
-
* // AssertionError: The expression evaluated to a falsy value:
|
|
321
|
-
* //
|
|
322
|
-
* // assert.ok(0)
|
|
323
|
-
* ```
|
|
324
|
-
*
|
|
325
|
-
* ```js
|
|
326
219
|
* import assert from 'assert/strict';
|
|
327
220
|
*
|
|
328
221
|
* // Using `assert()` works the same:
|
|
@@ -331,16 +224,6 @@ declare module 'assert' {
|
|
|
331
224
|
* //
|
|
332
225
|
* // assert(0)
|
|
333
226
|
* ```
|
|
334
|
-
*
|
|
335
|
-
* ```js
|
|
336
|
-
* const assert = require('assert');
|
|
337
|
-
*
|
|
338
|
-
* // Using `assert()` works the same:
|
|
339
|
-
* assert(0);
|
|
340
|
-
* // AssertionError: The expression evaluated to a falsy value:
|
|
341
|
-
* //
|
|
342
|
-
* // assert(0)
|
|
343
|
-
* ```
|
|
344
227
|
* @since v0.1.21
|
|
345
228
|
*/
|
|
346
229
|
function ok(value: unknown, message?: string | Error): asserts value;
|
|
@@ -373,22 +256,6 @@ declare module 'assert' {
|
|
|
373
256
|
* // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
|
|
374
257
|
* ```
|
|
375
258
|
*
|
|
376
|
-
* ```js
|
|
377
|
-
* const assert = require('assert');
|
|
378
|
-
*
|
|
379
|
-
* assert.equal(1, 1);
|
|
380
|
-
* // OK, 1 == 1
|
|
381
|
-
* assert.equal(1, '1');
|
|
382
|
-
* // OK, 1 == '1'
|
|
383
|
-
* assert.equal(NaN, NaN);
|
|
384
|
-
* // OK
|
|
385
|
-
*
|
|
386
|
-
* assert.equal(1, 2);
|
|
387
|
-
* // AssertionError: 1 == 2
|
|
388
|
-
* assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
|
|
389
|
-
* // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
|
|
390
|
-
* ```
|
|
391
|
-
*
|
|
392
259
|
* 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
|
|
393
260
|
* error message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
|
|
394
261
|
* @since v0.1.21
|
|
@@ -420,19 +287,6 @@ declare module 'assert' {
|
|
|
420
287
|
* // AssertionError: 1 != '1'
|
|
421
288
|
* ```
|
|
422
289
|
*
|
|
423
|
-
* ```js
|
|
424
|
-
* const assert = require('assert');
|
|
425
|
-
*
|
|
426
|
-
* assert.notEqual(1, 2);
|
|
427
|
-
* // OK
|
|
428
|
-
*
|
|
429
|
-
* assert.notEqual(1, 1);
|
|
430
|
-
* // AssertionError: 1 != 1
|
|
431
|
-
*
|
|
432
|
-
* assert.notEqual(1, '1');
|
|
433
|
-
* // AssertionError: 1 != '1'
|
|
434
|
-
* ```
|
|
435
|
-
*
|
|
436
290
|
* 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
|
|
437
291
|
* message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
|
|
438
292
|
* @since v0.1.21
|
|
@@ -500,39 +354,6 @@ declare module 'assert' {
|
|
|
500
354
|
* // OK
|
|
501
355
|
* ```
|
|
502
356
|
*
|
|
503
|
-
* ```js
|
|
504
|
-
* const assert = require('assert');
|
|
505
|
-
*
|
|
506
|
-
* const obj1 = {
|
|
507
|
-
* a: {
|
|
508
|
-
* b: 1
|
|
509
|
-
* }
|
|
510
|
-
* };
|
|
511
|
-
* const obj2 = {
|
|
512
|
-
* a: {
|
|
513
|
-
* b: 2
|
|
514
|
-
* }
|
|
515
|
-
* };
|
|
516
|
-
* const obj3 = {
|
|
517
|
-
* a: {
|
|
518
|
-
* b: 1
|
|
519
|
-
* }
|
|
520
|
-
* };
|
|
521
|
-
* const obj4 = Object.create(obj1);
|
|
522
|
-
*
|
|
523
|
-
* assert.notDeepEqual(obj1, obj1);
|
|
524
|
-
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
|
525
|
-
*
|
|
526
|
-
* assert.notDeepEqual(obj1, obj2);
|
|
527
|
-
* // OK
|
|
528
|
-
*
|
|
529
|
-
* assert.notDeepEqual(obj1, obj3);
|
|
530
|
-
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
|
531
|
-
*
|
|
532
|
-
* assert.notDeepEqual(obj1, obj4);
|
|
533
|
-
* // OK
|
|
534
|
-
* ```
|
|
535
|
-
*
|
|
536
357
|
* 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
|
|
537
358
|
* error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
|
538
359
|
* instead of the `AssertionError`.
|
|
@@ -571,34 +392,6 @@ declare module 'assert' {
|
|
|
571
392
|
* // TypeError: Inputs are not identical
|
|
572
393
|
* ```
|
|
573
394
|
*
|
|
574
|
-
* ```js
|
|
575
|
-
* const assert = require('assert/strict');
|
|
576
|
-
*
|
|
577
|
-
* assert.strictEqual(1, 2);
|
|
578
|
-
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
|
579
|
-
* //
|
|
580
|
-
* // 1 !== 2
|
|
581
|
-
*
|
|
582
|
-
* assert.strictEqual(1, 1);
|
|
583
|
-
* // OK
|
|
584
|
-
*
|
|
585
|
-
* assert.strictEqual('Hello foobar', 'Hello World!');
|
|
586
|
-
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
|
587
|
-
* // + actual - expected
|
|
588
|
-
* //
|
|
589
|
-
* // + 'Hello foobar'
|
|
590
|
-
* // - 'Hello World!'
|
|
591
|
-
* // ^
|
|
592
|
-
*
|
|
593
|
-
* const apples = 1;
|
|
594
|
-
* const oranges = 2;
|
|
595
|
-
* assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);
|
|
596
|
-
* // AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2
|
|
597
|
-
*
|
|
598
|
-
* assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
|
|
599
|
-
* // TypeError: Inputs are not identical
|
|
600
|
-
* ```
|
|
601
|
-
*
|
|
602
395
|
* 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
|
|
603
396
|
* default error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
|
604
397
|
* instead of the `AssertionError`.
|
|
@@ -624,21 +417,6 @@ declare module 'assert' {
|
|
|
624
417
|
* // OK
|
|
625
418
|
* ```
|
|
626
419
|
*
|
|
627
|
-
* ```js
|
|
628
|
-
* const assert = require('assert/strict');
|
|
629
|
-
*
|
|
630
|
-
* assert.notStrictEqual(1, 2);
|
|
631
|
-
* // OK
|
|
632
|
-
*
|
|
633
|
-
* assert.notStrictEqual(1, 1);
|
|
634
|
-
* // AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
|
|
635
|
-
* //
|
|
636
|
-
* // 1
|
|
637
|
-
*
|
|
638
|
-
* assert.notStrictEqual(1, '1');
|
|
639
|
-
* // OK
|
|
640
|
-
* ```
|
|
641
|
-
*
|
|
642
420
|
* 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
|
|
643
421
|
* default error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
|
644
422
|
* instead of the `AssertionError`.
|
|
@@ -662,13 +440,6 @@ declare module 'assert' {
|
|
|
662
440
|
* // OK
|
|
663
441
|
* ```
|
|
664
442
|
*
|
|
665
|
-
* ```js
|
|
666
|
-
* const assert = require('assert/strict');
|
|
667
|
-
*
|
|
668
|
-
* assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
|
|
669
|
-
* // OK
|
|
670
|
-
* ```
|
|
671
|
-
*
|
|
672
443
|
* If the values are deeply and strictly equal, an `AssertionError` is thrown
|
|
673
444
|
* with a `message` property set equal to the value of the `message` parameter. If
|
|
674
445
|
* the `message` parameter is undefined, a default error message is assigned. If
|
|
@@ -762,75 +533,6 @@ declare module 'assert' {
|
|
|
762
533
|
* );
|
|
763
534
|
* ```
|
|
764
535
|
*
|
|
765
|
-
* ```js
|
|
766
|
-
* const assert = require('assert/strict');
|
|
767
|
-
*
|
|
768
|
-
* const err = new TypeError('Wrong value');
|
|
769
|
-
* err.code = 404;
|
|
770
|
-
* err.foo = 'bar';
|
|
771
|
-
* err.info = {
|
|
772
|
-
* nested: true,
|
|
773
|
-
* baz: 'text'
|
|
774
|
-
* };
|
|
775
|
-
* err.reg = /abc/i;
|
|
776
|
-
*
|
|
777
|
-
* assert.throws(
|
|
778
|
-
* () => {
|
|
779
|
-
* throw err;
|
|
780
|
-
* },
|
|
781
|
-
* {
|
|
782
|
-
* name: 'TypeError',
|
|
783
|
-
* message: 'Wrong value',
|
|
784
|
-
* info: {
|
|
785
|
-
* nested: true,
|
|
786
|
-
* baz: 'text'
|
|
787
|
-
* }
|
|
788
|
-
* // Only properties on the validation object will be tested for.
|
|
789
|
-
* // Using nested objects requires all properties to be present. Otherwise
|
|
790
|
-
* // the validation is going to fail.
|
|
791
|
-
* }
|
|
792
|
-
* );
|
|
793
|
-
*
|
|
794
|
-
* // Using regular expressions to validate error properties:
|
|
795
|
-
* throws(
|
|
796
|
-
* () => {
|
|
797
|
-
* throw err;
|
|
798
|
-
* },
|
|
799
|
-
* {
|
|
800
|
-
* // The `name` and `message` properties are strings and using regular
|
|
801
|
-
* // expressions on those will match against the string. If they fail, an
|
|
802
|
-
* // error is thrown.
|
|
803
|
-
* name: /^TypeError$/,
|
|
804
|
-
* message: /Wrong/,
|
|
805
|
-
* foo: 'bar',
|
|
806
|
-
* info: {
|
|
807
|
-
* nested: true,
|
|
808
|
-
* // It is not possible to use regular expressions for nested properties!
|
|
809
|
-
* baz: 'text'
|
|
810
|
-
* },
|
|
811
|
-
* // The `reg` property contains a regular expression and only if the
|
|
812
|
-
* // validation object contains an identical regular expression, it is going
|
|
813
|
-
* // to pass.
|
|
814
|
-
* reg: /abc/i
|
|
815
|
-
* }
|
|
816
|
-
* );
|
|
817
|
-
*
|
|
818
|
-
* // Fails due to the different `message` and `name` properties:
|
|
819
|
-
* throws(
|
|
820
|
-
* () => {
|
|
821
|
-
* const otherErr = new Error('Not found');
|
|
822
|
-
* // Copy all enumerable properties from `err` to `otherErr`.
|
|
823
|
-
* for (const [key, value] of Object.entries(err)) {
|
|
824
|
-
* otherErr[key] = value;
|
|
825
|
-
* }
|
|
826
|
-
* throw otherErr;
|
|
827
|
-
* },
|
|
828
|
-
* // The error's `message` and `name` properties will also be checked when using
|
|
829
|
-
* // an error as validation object.
|
|
830
|
-
* err
|
|
831
|
-
* );
|
|
832
|
-
* ```
|
|
833
|
-
*
|
|
834
536
|
* Validate instanceof using constructor:
|
|
835
537
|
*
|
|
836
538
|
* ```js
|
|
@@ -844,17 +546,6 @@ declare module 'assert' {
|
|
|
844
546
|
* );
|
|
845
547
|
* ```
|
|
846
548
|
*
|
|
847
|
-
* ```js
|
|
848
|
-
* const assert = require('assert/strict');
|
|
849
|
-
*
|
|
850
|
-
* assert.throws(
|
|
851
|
-
* () => {
|
|
852
|
-
* throw new Error('Wrong value');
|
|
853
|
-
* },
|
|
854
|
-
* Error
|
|
855
|
-
* );
|
|
856
|
-
* ```
|
|
857
|
-
*
|
|
858
549
|
* Validate error message using [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions):
|
|
859
550
|
*
|
|
860
551
|
* Using a regular expression runs `.toString` on the error object, and will
|
|
@@ -871,17 +562,6 @@ declare module 'assert' {
|
|
|
871
562
|
* );
|
|
872
563
|
* ```
|
|
873
564
|
*
|
|
874
|
-
* ```js
|
|
875
|
-
* const assert = require('assert/strict');
|
|
876
|
-
*
|
|
877
|
-
* assert.throws(
|
|
878
|
-
* () => {
|
|
879
|
-
* throw new Error('Wrong value');
|
|
880
|
-
* },
|
|
881
|
-
* /^Error: Wrong value$/
|
|
882
|
-
* );
|
|
883
|
-
* ```
|
|
884
|
-
*
|
|
885
565
|
* Custom error validation:
|
|
886
566
|
*
|
|
887
567
|
* The function must return `true` to indicate all internal validations passed.
|
|
@@ -908,27 +588,6 @@ declare module 'assert' {
|
|
|
908
588
|
* );
|
|
909
589
|
* ```
|
|
910
590
|
*
|
|
911
|
-
* ```js
|
|
912
|
-
* const assert = require('assert/strict');
|
|
913
|
-
*
|
|
914
|
-
* assert.throws(
|
|
915
|
-
* () => {
|
|
916
|
-
* throw new Error('Wrong value');
|
|
917
|
-
* },
|
|
918
|
-
* (err) => {
|
|
919
|
-
* assert(err instanceof Error);
|
|
920
|
-
* assert(/value/.test(err));
|
|
921
|
-
* // Avoid returning anything from validation functions besides `true`.
|
|
922
|
-
* // Otherwise, it's not clear what part of the validation failed. Instead,
|
|
923
|
-
* // throw an error about the specific validation that failed (as done in this
|
|
924
|
-
* // example) and add as much helpful debugging information to that error as
|
|
925
|
-
* // possible.
|
|
926
|
-
* return true;
|
|
927
|
-
* },
|
|
928
|
-
* 'unexpected error'
|
|
929
|
-
* );
|
|
930
|
-
* ```
|
|
931
|
-
*
|
|
932
591
|
* `error` cannot be a string. If a string is provided as the second
|
|
933
592
|
* 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
|
|
934
593
|
* message as the thrown error message is going to result in an`ERR_AMBIGUOUS_ARGUMENT` error. Please read the example below carefully if using
|
|
@@ -970,42 +629,6 @@ declare module 'assert' {
|
|
|
970
629
|
* // AssertionError [ERR_ASSERTION]
|
|
971
630
|
* ```
|
|
972
631
|
*
|
|
973
|
-
* ```js
|
|
974
|
-
* const assert = require('assert/strict');
|
|
975
|
-
*
|
|
976
|
-
* function throwingFirst() {
|
|
977
|
-
* throw new Error('First');
|
|
978
|
-
* }
|
|
979
|
-
*
|
|
980
|
-
* function throwingSecond() {
|
|
981
|
-
* throw new Error('Second');
|
|
982
|
-
* }
|
|
983
|
-
*
|
|
984
|
-
* function notThrowing() {}
|
|
985
|
-
*
|
|
986
|
-
* // The second argument is a string and the input function threw an Error.
|
|
987
|
-
* // The first case will not throw as it does not match for the error message
|
|
988
|
-
* // thrown by the input function!
|
|
989
|
-
* assert.throws(throwingFirst, 'Second');
|
|
990
|
-
* // In the next example the message has no benefit over the message from the
|
|
991
|
-
* // error and since it is not clear if the user intended to actually match
|
|
992
|
-
* // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.
|
|
993
|
-
* assert.throws(throwingSecond, 'Second');
|
|
994
|
-
* // TypeError [ERR_AMBIGUOUS_ARGUMENT]
|
|
995
|
-
*
|
|
996
|
-
* // The string is only used (as message) in case the function does not throw:
|
|
997
|
-
* assert.throws(notThrowing, 'Second');
|
|
998
|
-
* // AssertionError [ERR_ASSERTION]: Missing expected exception: Second
|
|
999
|
-
*
|
|
1000
|
-
* // If it was intended to match for the error message do this instead:
|
|
1001
|
-
* // It does not throw because the error messages match.
|
|
1002
|
-
* assert.throws(throwingSecond, /Second$/);
|
|
1003
|
-
*
|
|
1004
|
-
* // If the error message does not match, an AssertionError is thrown.
|
|
1005
|
-
* assert.throws(throwingFirst, /Second$/);
|
|
1006
|
-
* // AssertionError [ERR_ASSERTION]
|
|
1007
|
-
* ```
|
|
1008
|
-
*
|
|
1009
632
|
* Due to the confusing error-prone notation, avoid a string as the second
|
|
1010
633
|
* argument.
|
|
1011
634
|
* @since v0.1.21
|
|
@@ -1044,17 +667,6 @@ declare module 'assert' {
|
|
|
1044
667
|
* );
|
|
1045
668
|
* ```
|
|
1046
669
|
*
|
|
1047
|
-
* ```js
|
|
1048
|
-
* const assert = require('assert/strict');
|
|
1049
|
-
*
|
|
1050
|
-
* assert.doesNotThrow(
|
|
1051
|
-
* () => {
|
|
1052
|
-
* throw new TypeError('Wrong value');
|
|
1053
|
-
* },
|
|
1054
|
-
* SyntaxError
|
|
1055
|
-
* );
|
|
1056
|
-
* ```
|
|
1057
|
-
*
|
|
1058
670
|
* However, the following will result in an `AssertionError` with the message
|
|
1059
671
|
* 'Got unwanted exception...':
|
|
1060
672
|
*
|
|
@@ -1069,17 +681,6 @@ declare module 'assert' {
|
|
|
1069
681
|
* );
|
|
1070
682
|
* ```
|
|
1071
683
|
*
|
|
1072
|
-
* ```js
|
|
1073
|
-
* const assert = require('assert/strict');
|
|
1074
|
-
*
|
|
1075
|
-
* assert.doesNotThrow(
|
|
1076
|
-
* () => {
|
|
1077
|
-
* throw new TypeError('Wrong value');
|
|
1078
|
-
* },
|
|
1079
|
-
* TypeError
|
|
1080
|
-
* );
|
|
1081
|
-
* ```
|
|
1082
|
-
*
|
|
1083
684
|
* 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:
|
|
1084
685
|
*
|
|
1085
686
|
* ```js
|
|
@@ -1094,19 +695,6 @@ declare module 'assert' {
|
|
|
1094
695
|
* );
|
|
1095
696
|
* // Throws: AssertionError: Got unwanted exception: Whoops
|
|
1096
697
|
* ```
|
|
1097
|
-
*
|
|
1098
|
-
* ```js
|
|
1099
|
-
* const assert = require('assert/strict');
|
|
1100
|
-
*
|
|
1101
|
-
* assert.doesNotThrow(
|
|
1102
|
-
* () => {
|
|
1103
|
-
* throw new TypeError('Wrong value');
|
|
1104
|
-
* },
|
|
1105
|
-
* /Wrong value/,
|
|
1106
|
-
* 'Whoops'
|
|
1107
|
-
* );
|
|
1108
|
-
* // Throws: AssertionError: Got unwanted exception: Whoops
|
|
1109
|
-
* ```
|
|
1110
698
|
* @since v0.1.21
|
|
1111
699
|
*/
|
|
1112
700
|
function doesNotThrow(block: () => unknown, message?: string | Error): void;
|
|
@@ -1141,32 +729,6 @@ declare module 'assert' {
|
|
|
1141
729
|
* // at ifErrorFrame
|
|
1142
730
|
* // at errorFrame
|
|
1143
731
|
* ```
|
|
1144
|
-
*
|
|
1145
|
-
* ```js
|
|
1146
|
-
* const assert = require('assert/strict');
|
|
1147
|
-
*
|
|
1148
|
-
* assert.ifError(null);
|
|
1149
|
-
* // OK
|
|
1150
|
-
* assert.ifError(0);
|
|
1151
|
-
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
|
|
1152
|
-
* assert.ifError('error');
|
|
1153
|
-
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
|
|
1154
|
-
* assert.ifError(new Error());
|
|
1155
|
-
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
|
|
1156
|
-
*
|
|
1157
|
-
* // Create some random error frames.
|
|
1158
|
-
* let err;
|
|
1159
|
-
* (function errorFrame() {
|
|
1160
|
-
* err = new Error('test error');
|
|
1161
|
-
* })();
|
|
1162
|
-
*
|
|
1163
|
-
* (function ifErrorFrame() {
|
|
1164
|
-
* assert.ifError(err);
|
|
1165
|
-
* })();
|
|
1166
|
-
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
|
|
1167
|
-
* // at ifErrorFrame
|
|
1168
|
-
* // at errorFrame
|
|
1169
|
-
* ```
|
|
1170
732
|
* @since v0.1.97
|
|
1171
733
|
*/
|
|
1172
734
|
function ifError(value: unknown): asserts value is null | undefined;
|
|
@@ -1203,22 +765,6 @@ declare module 'assert' {
|
|
|
1203
765
|
* ```
|
|
1204
766
|
*
|
|
1205
767
|
* ```js
|
|
1206
|
-
* const assert = require('assert/strict');
|
|
1207
|
-
*
|
|
1208
|
-
* (async () => {
|
|
1209
|
-
* await assert.rejects(
|
|
1210
|
-
* async () => {
|
|
1211
|
-
* throw new TypeError('Wrong value');
|
|
1212
|
-
* },
|
|
1213
|
-
* {
|
|
1214
|
-
* name: 'TypeError',
|
|
1215
|
-
* message: 'Wrong value'
|
|
1216
|
-
* }
|
|
1217
|
-
* );
|
|
1218
|
-
* })();
|
|
1219
|
-
* ```
|
|
1220
|
-
*
|
|
1221
|
-
* ```js
|
|
1222
768
|
* import assert from 'assert/strict';
|
|
1223
769
|
*
|
|
1224
770
|
* await assert.rejects(
|
|
@@ -1234,23 +780,6 @@ declare module 'assert' {
|
|
|
1234
780
|
* ```
|
|
1235
781
|
*
|
|
1236
782
|
* ```js
|
|
1237
|
-
* const assert = require('assert/strict');
|
|
1238
|
-
*
|
|
1239
|
-
* (async () => {
|
|
1240
|
-
* await assert.rejects(
|
|
1241
|
-
* async () => {
|
|
1242
|
-
* throw new TypeError('Wrong value');
|
|
1243
|
-
* },
|
|
1244
|
-
* (err) => {
|
|
1245
|
-
* assert.strictEqual(err.name, 'TypeError');
|
|
1246
|
-
* assert.strictEqual(err.message, 'Wrong value');
|
|
1247
|
-
* return true;
|
|
1248
|
-
* }
|
|
1249
|
-
* );
|
|
1250
|
-
* })();
|
|
1251
|
-
* ```
|
|
1252
|
-
*
|
|
1253
|
-
* ```js
|
|
1254
783
|
* import assert from 'assert/strict';
|
|
1255
784
|
*
|
|
1256
785
|
* assert.rejects(
|
|
@@ -1261,17 +790,6 @@ declare module 'assert' {
|
|
|
1261
790
|
* });
|
|
1262
791
|
* ```
|
|
1263
792
|
*
|
|
1264
|
-
* ```js
|
|
1265
|
-
* const assert = require('assert/strict');
|
|
1266
|
-
*
|
|
1267
|
-
* assert.rejects(
|
|
1268
|
-
* Promise.reject(new Error('Wrong value')),
|
|
1269
|
-
* Error
|
|
1270
|
-
* ).then(() => {
|
|
1271
|
-
* // ...
|
|
1272
|
-
* });
|
|
1273
|
-
* ```
|
|
1274
|
-
*
|
|
1275
793
|
* `error` cannot be a string. If a string is provided as the second
|
|
1276
794
|
* 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
|
|
1277
795
|
* example in {@link throws} carefully if using a string as the second
|
|
@@ -1313,19 +831,6 @@ declare module 'assert' {
|
|
|
1313
831
|
* ```
|
|
1314
832
|
*
|
|
1315
833
|
* ```js
|
|
1316
|
-
* const assert = require('assert/strict');
|
|
1317
|
-
*
|
|
1318
|
-
* (async () => {
|
|
1319
|
-
* await assert.doesNotReject(
|
|
1320
|
-
* async () => {
|
|
1321
|
-
* throw new TypeError('Wrong value');
|
|
1322
|
-
* },
|
|
1323
|
-
* SyntaxError
|
|
1324
|
-
* );
|
|
1325
|
-
* })();
|
|
1326
|
-
* ```
|
|
1327
|
-
*
|
|
1328
|
-
* ```js
|
|
1329
834
|
* import assert from 'assert/strict';
|
|
1330
835
|
*
|
|
1331
836
|
* assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
|
|
@@ -1333,15 +838,6 @@ declare module 'assert' {
|
|
|
1333
838
|
* // ...
|
|
1334
839
|
* });
|
|
1335
840
|
* ```
|
|
1336
|
-
*
|
|
1337
|
-
* ```js
|
|
1338
|
-
* const assert = require('assert/strict');
|
|
1339
|
-
*
|
|
1340
|
-
* assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
|
|
1341
|
-
* .then(() => {
|
|
1342
|
-
* // ...
|
|
1343
|
-
* });
|
|
1344
|
-
* ```
|
|
1345
841
|
* @since v10.0.0
|
|
1346
842
|
*/
|
|
1347
843
|
function doesNotReject(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
|
|
@@ -1362,19 +858,6 @@ declare module 'assert' {
|
|
|
1362
858
|
* // OK
|
|
1363
859
|
* ```
|
|
1364
860
|
*
|
|
1365
|
-
* ```js
|
|
1366
|
-
* const assert = require('assert/strict');
|
|
1367
|
-
*
|
|
1368
|
-
* assert.match('I will fail', /pass/);
|
|
1369
|
-
* // AssertionError [ERR_ASSERTION]: The input did not match the regular ...
|
|
1370
|
-
*
|
|
1371
|
-
* assert.match(123, /pass/);
|
|
1372
|
-
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
|
1373
|
-
*
|
|
1374
|
-
* assert.match('I will pass', /pass/);
|
|
1375
|
-
* // OK
|
|
1376
|
-
* ```
|
|
1377
|
-
*
|
|
1378
861
|
* 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
|
|
1379
862
|
* to the value of the `message` parameter. If the `message` parameter is
|
|
1380
863
|
* undefined, a default error message is assigned. If the `message` parameter is an
|
|
@@ -1398,19 +881,6 @@ declare module 'assert' {
|
|
|
1398
881
|
* // OK
|
|
1399
882
|
* ```
|
|
1400
883
|
*
|
|
1401
|
-
* ```js
|
|
1402
|
-
* const assert = require('assert/strict');
|
|
1403
|
-
*
|
|
1404
|
-
* assert.doesNotMatch('I will fail', /fail/);
|
|
1405
|
-
* // AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
|
|
1406
|
-
*
|
|
1407
|
-
* assert.doesNotMatch(123, /pass/);
|
|
1408
|
-
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
|
1409
|
-
*
|
|
1410
|
-
* assert.doesNotMatch('I will pass', /different/);
|
|
1411
|
-
* // OK
|
|
1412
|
-
* ```
|
|
1413
|
-
*
|
|
1414
884
|
* 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
|
|
1415
885
|
* to the value of the `message` parameter. If the `message` parameter is
|
|
1416
886
|
* undefined, a default error message is assigned. If the `message` parameter is an
|