@@ -10,6 +10,7 @@ The `assert` module provides a set of assertion functions for verifying
10
10
invariants.
11
11
12
12
## Strict assertion mode
13
+
13
14
<!-- YAML
14
15
added: v9.9.0
15
16
changes:
@@ -138,6 +139,7 @@ Indicates the failure of an assertion. All errors thrown by the `assert` module
138
139
will be instances of the ` AssertionError ` class.
139
140
140
141
### ` new assert.AssertionError(options) `
142
+
141
143
<!-- YAML
142
144
added: v0.1.21
143
145
-->
@@ -216,6 +218,7 @@ try {
216
218
```
217
219
218
220
## Class: ` assert.CallTracker `
221
+
219
222
<!-- YAML
220
223
added:
221
224
- v14.2.0
@@ -227,6 +230,7 @@ added:
227
230
This feature is currently experimental and behavior might still change.
228
231
229
232
### ` new assert.CallTracker() `
233
+
230
234
<!-- YAML
231
235
added:
232
236
- v14.2.0
@@ -278,6 +282,7 @@ process.on('exit', () => {
278
282
```
279
283
280
284
### ` tracker.calls([fn][, exact]) `
285
+
281
286
<!-- YAML
282
287
added:
283
288
- v14.2.0
@@ -320,6 +325,7 @@ const callsfunc = tracker.calls(func);
320
325
```
321
326
322
327
### ` tracker.report() `
328
+
323
329
<!-- YAML
324
330
added:
325
331
- v14.2.0
@@ -396,6 +402,7 @@ tracker.report();
396
402
```
397
403
398
404
### ` tracker.verify() `
405
+
399
406
<!-- YAML
400
407
added:
401
408
- v14.2.0
@@ -443,6 +450,7 @@ tracker.verify();
443
450
```
444
451
445
452
## ` assert(value[, message]) `
453
+
446
454
<!-- YAML
447
455
added: v0.5.9
448
456
-->
@@ -453,6 +461,7 @@ added: v0.5.9
453
461
An alias of [ ` assert.ok() ` ] [ ] .
454
462
455
463
## ` assert.deepEqual(actual, expected[, message]) `
464
+
456
465
<!-- YAML
457
466
added: v0.1.21
458
467
changes:
@@ -629,6 +638,7 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
629
638
[ ` AssertionError ` ] [ ] .
630
639
631
640
## ` assert.deepStrictEqual(actual, expected[, message]) `
641
+
632
642
<!-- YAML
633
643
added: v1.2.0
634
644
changes:
@@ -879,6 +889,7 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
879
889
` AssertionError ` .
880
890
881
891
## ` assert.doesNotMatch(string, regexp[, message]) `
892
+
882
893
<!-- YAML
883
894
added:
884
895
- v13.6.0
@@ -929,6 +940,7 @@ instance of an [`Error`][] then it will be thrown instead of the
929
940
[ ` AssertionError ` ] [ ] .
930
941
931
942
## ` assert.doesNotReject(asyncFn[, error][, message]) `
943
+
932
944
<!-- YAML
933
945
added: v10.0.0
934
946
-->
@@ -959,6 +971,7 @@ Besides the async nature to await the completion behaves identically to
959
971
[ ` assert.doesNotThrow() ` ] [ ] .
960
972
961
973
<!-- eslint-disable no-restricted-syntax -->
974
+
962
975
``` mjs
963
976
import assert from ' assert/strict' ;
964
977
@@ -984,6 +997,7 @@ const assert = require('assert/strict');
984
997
```
985
998
986
999
<!-- eslint-disable no-restricted-syntax -->
1000
+
987
1001
``` mjs
988
1002
import assert from ' assert/strict' ;
989
1003
@@ -994,6 +1008,7 @@ assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
994
1008
```
995
1009
996
1010
<!-- eslint-disable no-restricted-syntax -->
1011
+
997
1012
``` cjs
998
1013
const assert = require (' assert/strict' );
999
1014
@@ -1004,6 +1019,7 @@ assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
1004
1019
```
1005
1020
1006
1021
## ` assert.doesNotThrow(fn[, error][, message]) `
1022
+
1007
1023
<!-- YAML
1008
1024
added: v0.1.21
1009
1025
changes:
@@ -1043,6 +1059,7 @@ The following, for instance, will throw the [`TypeError`][] because there is no
1043
1059
matching error type in the assertion:
1044
1060
1045
1061
<!-- eslint-disable no-restricted-syntax -->
1062
+
1046
1063
``` mjs
1047
1064
import assert from ' assert/strict' ;
1048
1065
@@ -1055,6 +1072,7 @@ assert.doesNotThrow(
1055
1072
```
1056
1073
1057
1074
<!-- eslint-disable no-restricted-syntax -->
1075
+
1058
1076
``` cjs
1059
1077
const assert = require (' assert/strict' );
1060
1078
@@ -1070,6 +1088,7 @@ However, the following will result in an [`AssertionError`][] with the message
1070
1088
'Got unwanted exception...':
1071
1089
1072
1090
<!-- eslint-disable no-restricted-syntax -->
1091
+
1073
1092
``` mjs
1074
1093
import assert from ' assert/strict' ;
1075
1094
@@ -1082,6 +1101,7 @@ assert.doesNotThrow(
1082
1101
```
1083
1102
1084
1103
<!-- eslint-disable no-restricted-syntax -->
1104
+
1085
1105
``` cjs
1086
1106
const assert = require (' assert/strict' );
1087
1107
@@ -1098,6 +1118,7 @@ parameter, the value of `message` will be appended to the [`AssertionError`][]
1098
1118
message:
1099
1119
1100
1120
<!-- eslint-disable no-restricted-syntax -->
1121
+
1101
1122
``` mjs
1102
1123
import assert from ' assert/strict' ;
1103
1124
@@ -1112,6 +1133,7 @@ assert.doesNotThrow(
1112
1133
```
1113
1134
1114
1135
<!-- eslint-disable no-restricted-syntax -->
1136
+
1115
1137
``` cjs
1116
1138
const assert = require (' assert/strict' );
1117
1139
@@ -1126,6 +1148,7 @@ assert.doesNotThrow(
1126
1148
```
1127
1149
1128
1150
## ` assert.equal(actual, expected[, message]) `
1151
+
1129
1152
<!-- YAML
1130
1153
added: v0.1.21
1131
1154
changes:
@@ -1196,6 +1219,7 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
1196
1219
` AssertionError ` .
1197
1220
1198
1221
## ` assert.fail([message]) `
1222
+
1199
1223
<!-- YAML
1200
1224
added: v0.1.21
1201
1225
-->
@@ -1236,6 +1260,7 @@ Using `assert.fail()` with more than two arguments is possible but deprecated.
1236
1260
See below for further details.
1237
1261
1238
1262
## ` assert.fail(actual, expected[, message[, operator[, stackStartFn]]]) `
1263
+
1239
1264
<!-- YAML
1240
1265
added: v0.1.21
1241
1266
changes:
@@ -1333,6 +1358,7 @@ suppressFrame();
1333
1358
```
1334
1359
1335
1360
## ` assert.ifError(value) `
1361
+
1336
1362
<!-- YAML
1337
1363
added: v0.1.97
1338
1364
changes:
@@ -1406,6 +1432,7 @@ let err;
1406
1432
```
1407
1433
1408
1434
## ` assert.match(string, regexp[, message]) `
1435
+
1409
1436
<!-- YAML
1410
1437
added:
1411
1438
- v13.6.0
@@ -1456,6 +1483,7 @@ instance of an [`Error`][] then it will be thrown instead of the
1456
1483
[ ` AssertionError ` ] [ ] .
1457
1484
1458
1485
## ` assert.notDeepEqual(actual, expected[, message]) `
1486
+
1459
1487
<!-- YAML
1460
1488
added: v0.1.21
1461
1489
changes:
@@ -1579,6 +1607,7 @@ If the values are deeply equal, an [`AssertionError`][] is thrown with a
1579
1607
instead of the ` AssertionError ` .
1580
1608
1581
1609
## ` assert.notDeepStrictEqual(actual, expected[, message]) `
1610
+
1582
1611
<!-- YAML
1583
1612
added: v1.2.0
1584
1613
changes:
@@ -1638,6 +1667,7 @@ the `message` parameter is an instance of an [`Error`][] then it will be thrown
1638
1667
instead of the [ ` AssertionError ` ] [ ] .
1639
1668
1640
1669
## ` assert.notEqual(actual, expected[, message]) `
1670
+
1641
1671
<!-- YAML
1642
1672
added: v0.1.21
1643
1673
changes:
@@ -1702,6 +1732,7 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
1702
1732
` AssertionError ` .
1703
1733
1704
1734
## ` assert.notStrictEqual(actual, expected[, message]) `
1735
+
1705
1736
<!-- YAML
1706
1737
added: v0.1.21
1707
1738
changes:
@@ -1754,6 +1785,7 @@ If the values are strictly equal, an [`AssertionError`][] is thrown with a
1754
1785
instead of the ` AssertionError ` .
1755
1786
1756
1787
## ` assert.ok(value[, message]) `
1788
+
1757
1789
<!-- YAML
1758
1790
added: v0.1.21
1759
1791
changes:
@@ -1871,6 +1903,7 @@ assert(0);
1871
1903
```
1872
1904
1873
1905
## ` assert.rejects(asyncFn[, error][, message]) `
1906
+
1874
1907
<!-- YAML
1875
1908
added: v10.0.0
1876
1909
-->
@@ -1991,6 +2024,7 @@ example in [`assert.throws()`][] carefully if using a string as the second
1991
2024
argument gets considered.
1992
2025
1993
2026
## ` assert.strictEqual(actual, expected[, message]) `
2027
+
1994
2028
<!-- YAML
1995
2029
added: v0.1.21
1996
2030
changes:
@@ -2069,6 +2103,7 @@ If the values are not strictly equal, an [`AssertionError`][] is thrown with a
2069
2103
instead of the [ ` AssertionError ` ] [ ] .
2070
2104
2071
2105
## ` assert.throws(fn[, error][, message]) `
2106
+
2072
2107
<!-- YAML
2073
2108
added: v0.1.21
2074
2109
changes:
@@ -2347,6 +2382,7 @@ message as the thrown error message is going to result in an
2347
2382
a string as the second argument gets considered:
2348
2383
2349
2384
<!-- eslint-disable no-restricted-syntax -->
2385
+
2350
2386
``` mjs
2351
2387
import assert from ' assert/strict' ;
2352
2388
@@ -2384,6 +2420,7 @@ assert.throws(throwingFirst, /Second$/);
2384
2420
```
2385
2421
2386
2422
<!-- eslint-disable no-restricted-syntax -->
2423
+
2387
2424
``` cjs
2388
2425
const assert = require (' assert/strict' );
2389
2426
0 commit comments