@@ -22,14 +22,16 @@ An alias of [`assert.ok()`][] .
22
22
``` js
23
23
const assert = require (' assert' );
24
24
25
- assert (true ); // OK
26
- assert (1 ); // OK
25
+ assert (true );
26
+ // OK
27
+ assert (1 );
28
+ // OK
27
29
assert (false );
28
- // throws "AssertionError: false == true"
30
+ // throws "AssertionError: false == true"
29
31
assert (0 );
30
- // throws "AssertionError: 0 == true"
32
+ // throws "AssertionError: 0 == true"
31
33
assert (false , ' it\' s false' );
32
- // throws "AssertionError: it's false"
34
+ // throws "AssertionError: it's false"
33
35
```
34
36
35
37
## assert.deepEqual(actual, expected[ , message] )
@@ -75,18 +77,18 @@ const obj3 = {
75
77
const obj4 = Object .create (obj1);
76
78
77
79
assert .deepEqual (obj1, obj1);
78
- // OK, object is equal to itself
80
+ // OK, object is equal to itself
79
81
80
82
assert .deepEqual (obj1, obj2);
81
- // AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } }
82
- // values of b are different
83
+ // AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } }
84
+ // values of b are different
83
85
84
86
assert .deepEqual (obj1, obj3);
85
- // OK, objects are equal
87
+ // OK, objects are equal
86
88
87
89
assert .deepEqual (obj1, obj4);
88
- // AssertionError: { a: { b: 1 } } deepEqual {}
89
- // Prototypes are ignored
90
+ // AssertionError: { a: { b: 1 } } deepEqual {}
91
+ // Prototypes are ignored
90
92
```
91
93
92
94
If the values are not equal, an ` AssertionError ` is thrown with a ` message `
@@ -106,11 +108,11 @@ Second, object comparisons include a strict equality check of their prototypes.
106
108
const assert = require (' assert' );
107
109
108
110
assert .deepEqual ({a: 1 }, {a: ' 1' });
109
- // OK, because 1 == '1'
111
+ // OK, because 1 == '1'
110
112
111
113
assert .deepStrictEqual ({a: 1 }, {a: ' 1' });
112
- // AssertionError: { a: 1 } deepStrictEqual { a: '1' }
113
- // because 1 !== '1' using strict equality
114
+ // AssertionError: { a: 1 } deepStrictEqual { a: '1' }
115
+ // because 1 !== '1' using strict equality
114
116
```
115
117
116
118
If the values are not equal, an ` AssertionError ` is thrown with a ` message `
@@ -184,14 +186,14 @@ using the equal comparison operator ( `==` ).
184
186
const assert = require (' assert' );
185
187
186
188
assert .equal (1 , 1 );
187
- // OK, 1 == 1
189
+ // OK, 1 == 1
188
190
assert .equal (1 , ' 1' );
189
- // OK, 1 == '1'
191
+ // OK, 1 == '1'
190
192
191
193
assert .equal (1 , 2 );
192
- // AssertionError: 1 == 2
194
+ // AssertionError: 1 == 2
193
195
assert .equal ({a: {b: 1 }}, {a: {b: 1 }});
194
- // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
196
+ // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
195
197
```
196
198
197
199
If the values are not equal, an ` AssertionError ` is thrown with a ` message `
@@ -211,10 +213,10 @@ Otherwise, the error message is the value of `message`.
211
213
const assert = require (' assert' );
212
214
213
215
assert .fail (1 , 2 , undefined , ' >' );
214
- // AssertionError: 1 > 2
216
+ // AssertionError: 1 > 2
215
217
216
218
assert .fail (1 , 2 , ' whoops' , ' >' );
217
- // AssertionError: whoops
219
+ // AssertionError: whoops
218
220
```
219
221
220
222
## assert.ifError(value)
@@ -228,10 +230,14 @@ argument in callbacks.
228
230
``` js
229
231
const assert = require (' assert' );
230
232
231
- assert .ifError (0 ); // OK
232
- assert .ifError (1 ); // Throws 1
233
- assert .ifError (' error' ); // Throws 'error'
234
- assert .ifError (new Error ()); // Throws Error
233
+ assert .ifError (0 );
234
+ // OK
235
+ assert .ifError (1 );
236
+ // Throws 1
237
+ assert .ifError (' error' );
238
+ // Throws 'error'
239
+ assert .ifError (new Error ());
240
+ // Throws Error
235
241
```
236
242
237
243
## assert.notDeepEqual(actual, expected[ , message] )
@@ -262,16 +268,16 @@ const obj3 = {
262
268
const obj4 = Object .create (obj1);
263
269
264
270
assert .notDeepEqual (obj1, obj1);
265
- // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
271
+ // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
266
272
267
273
assert .notDeepEqual (obj1, obj2);
268
- // OK, obj1 and obj2 are not deeply equal
274
+ // OK, obj1 and obj2 are not deeply equal
269
275
270
276
assert .notDeepEqual (obj1, obj3);
271
- // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
277
+ // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
272
278
273
279
assert .notDeepEqual (obj1, obj4);
274
- // OK, obj1 and obj4 are not deeply equal
280
+ // OK, obj1 and obj2 are not deeply equal
275
281
```
276
282
277
283
If the values are deeply equal, an ` AssertionError ` is thrown with a ` message `
@@ -289,10 +295,10 @@ Tests for deep strict inequality. Opposite of [`assert.deepStrictEqual()`][].
289
295
const assert = require (' assert' );
290
296
291
297
assert .notDeepEqual ({a: 1 }, {a: ' 1' });
292
- // AssertionError: { a: 1 } notDeepEqual { a: '1' }
298
+ // AssertionError: { a: 1 } notDeepEqual { a: '1' }
293
299
294
300
assert .notDeepStrictEqual ({a: 1 }, {a: ' 1' });
295
- // OK
301
+ // OK
296
302
```
297
303
298
304
If the values are deeply and strictly equal, an ` AssertionError ` is thrown
@@ -311,13 +317,13 @@ Tests shallow, coercive inequality with the not equal comparison operator
311
317
const assert = require (' assert' );
312
318
313
319
assert .notEqual (1 , 2 );
314
- // OK
320
+ // OK
315
321
316
322
assert .notEqual (1 , 1 );
317
- // AssertionError: 1 != 1
323
+ // AssertionError: 1 != 1
318
324
319
325
assert .notEqual (1 , ' 1' );
320
- // AssertionError: 1 != '1'
326
+ // AssertionError: 1 != '1'
321
327
```
322
328
323
329
If the values are equal, an ` AssertionError ` is thrown with a ` message `
@@ -336,13 +342,13 @@ Tests strict inequality as determined by the strict not equal operator
336
342
const assert = require (' assert' );
337
343
338
344
assert .notStrictEqual (1 , 2 );
339
- // OK
345
+ // OK
340
346
341
347
assert .notStrictEqual (1 , 1 );
342
- // AssertionError: 1 != 1
348
+ // AssertionError: 1 != 1
343
349
344
350
assert .notStrictEqual (1 , ' 1' );
345
- // OK
351
+ // OK
346
352
```
347
353
348
354
If the values are strictly equal, an ` AssertionError ` is thrown with a
@@ -364,14 +370,16 @@ parameter is `undefined`, a default error message is assigned.
364
370
``` js
365
371
const assert = require (' assert' );
366
372
367
- assert .ok (true ); // OK
368
- assert .ok (1 ); // OK
373
+ assert .ok (true );
374
+ // OK
375
+ assert .ok (1 );
376
+ // OK
369
377
assert .ok (false );
370
- // throws "AssertionError: false == true"
378
+ // throws "AssertionError: false == true"
371
379
assert .ok (0 );
372
- // throws "AssertionError: 0 == true"
380
+ // throws "AssertionError: 0 == true"
373
381
assert .ok (false , ' it\' s false' );
374
- // throws "AssertionError: it's false"
382
+ // throws "AssertionError: it's false"
375
383
```
376
384
377
385
## assert.strictEqual(actual, expected[ , message] )
@@ -385,13 +393,13 @@ Tests strict equality as determined by the strict equality operator ( `===` ).
385
393
const assert = require (' assert' );
386
394
387
395
assert .strictEqual (1 , 2 );
388
- // AssertionError: 1 === 2
396
+ // AssertionError: 1 === 2
389
397
390
398
assert .strictEqual (1 , 1 );
391
- // OK
399
+ // OK
392
400
393
401
assert .strictEqual (1 , ' 1' );
394
- // AssertionError: 1 === '1'
402
+ // AssertionError: 1 === '1'
395
403
```
396
404
397
405
If the values are not strictly equal, an ` AssertionError ` is thrown with a
0 commit comments