@@ -108,15 +108,15 @@ Example error diff:
108
108
const assert = require (' assert' ).strict ;
109
109
110
110
assert .deepEqual ([[[1 , 2 , 3 ]], 4 , 5 ], [[[1 , 2 , ' 3' ]], 4 , 5 ]);
111
- // AssertionError: Input A expected to strictly deep-equal input B :
112
- // + expected - actual ... Lines skipped
111
+ // AssertionError: Expected inputs to be strictly deep-equal:
112
+ // + actual - expected ... Lines skipped
113
113
//
114
114
// [
115
115
// [
116
116
// ...
117
117
// 2,
118
- // - 3
119
- // + '3'
118
+ // + 3
119
+ // - '3'
120
120
// ],
121
121
// ...
122
122
// 5
@@ -315,11 +315,12 @@ const assert = require('assert').strict;
315
315
316
316
// This fails because 1 !== '1'.
317
317
assert .deepStrictEqual ({ a: 1 }, { a: ' 1' });
318
- // AssertionError: Input A expected to strictly deep-equal input B:
319
- // + expected - actual
318
+ // AssertionError: Expected inputs to be strictly deep-equal:
319
+ // + actual - expected
320
+ //
320
321
// {
321
- // - a: 1
322
- // + a: '1'
322
+ // + a: 1
323
+ // - a: '1'
323
324
// }
324
325
325
326
// The following objects don't have own properties
@@ -330,27 +331,30 @@ Object.setPrototypeOf(fakeDate, Date.prototype);
330
331
331
332
// Different [[Prototype]]:
332
333
assert .deepStrictEqual (object, fakeDate);
333
- // AssertionError: Input A expected to strictly deep-equal input B:
334
- // + expected - actual
335
- // - {}
336
- // + Date {}
334
+ // AssertionError: Expected inputs to be strictly deep-equal:
335
+ // + actual - expected
336
+ //
337
+ // + {}
338
+ // - Date {}
337
339
338
340
// Different type tags:
339
341
assert .deepStrictEqual (date, fakeDate);
340
- // AssertionError: Input A expected to strictly deep-equal input B:
341
- // + expected - actual
342
- // - 2018-04-26T00:49:08.604Z
343
- // + Date {}
342
+ // AssertionError: Expected inputs to be strictly deep-equal:
343
+ // + actual - expected
344
+ //
345
+ // + 2018-04-26T00:49:08.604Z
346
+ // - Date {}
344
347
345
348
assert .deepStrictEqual (NaN , NaN );
346
349
// OK, because of the SameValue comparison
347
350
348
351
// Different unwrapped numbers:
349
352
assert .deepStrictEqual (new Number (1 ), new Number (2 ));
350
- // AssertionError: Input A expected to strictly deep-equal input B:
351
- // + expected - actual
352
- // - [Number: 1]
353
- // + [Number: 2]
353
+ // AssertionError: Expected inputs to be strictly deep-equal:
354
+ // + actual - expected
355
+ //
356
+ // + [Number: 1]
357
+ // - [Number: 2]
354
358
355
359
assert .deepStrictEqual (new String (' foo' ), Object (' foo' ));
356
360
// OK because the object and the string are identical when unwrapped.
@@ -360,17 +364,20 @@ assert.deepStrictEqual(-0, -0);
360
364
361
365
// Different zeros using the SameValue Comparison:
362
366
assert .deepStrictEqual (0 , - 0 );
363
- // AssertionError: Input A expected to strictly deep-equal input B:
364
- // + expected - actual
365
- // - 0
366
- // + -0
367
+ // AssertionError: Expected inputs to be strictly deep-equal:
368
+ // + actual - expected
369
+ //
370
+ // + 0
371
+ // - -0
367
372
368
373
const symbol1 = Symbol ();
369
374
const symbol2 = Symbol ();
370
375
assert .deepStrictEqual ({ [symbol1]: 1 }, { [symbol1]: 1 });
371
376
// OK, because it is the same symbol on both objects.
377
+
372
378
assert .deepStrictEqual ({ [symbol1]: 1 }, { [symbol2]: 1 });
373
- // AssertionError [ERR_ASSERTION]: Input objects not identical:
379
+ // AssertionError [ERR_ASSERTION]: Inputs identical but not reference equal:
380
+ //
374
381
// {
375
382
// [Symbol()]: 1
376
383
// }
@@ -385,12 +392,13 @@ assert.deepStrictEqual(weakMap1, weakMap2);
385
392
386
393
// Fails because weakMap3 has a property that weakMap1 does not contain:
387
394
assert .deepStrictEqual (weakMap1, weakMap3);
388
- // AssertionError: Input A expected to strictly deep-equal input B:
389
- // + expected - actual
395
+ // AssertionError: Expected inputs to be strictly deep-equal:
396
+ // + actual - expected
397
+ //
390
398
// WeakMap {
391
- // - [items unknown]
392
- // + [items unknown],
393
- // + unequal: true
399
+ // + [items unknown]
400
+ // - [items unknown],
401
+ // - unequal: true
394
402
// }
395
403
```
396
404
@@ -875,7 +883,9 @@ assert.notStrictEqual(1, 2);
875
883
// OK
876
884
877
885
assert .notStrictEqual (1 , 1 );
878
- // AssertionError [ERR_ASSERTION]: Identical input passed to notStrictEqual: 1
886
+ // AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
887
+ //
888
+ // 1
879
889
880
890
assert .notStrictEqual (1 , ' 1' );
881
891
// OK
@@ -1031,19 +1041,20 @@ determined by the [SameValue Comparison][].
1031
1041
const assert = require (' assert' ).strict ;
1032
1042
1033
1043
assert .strictEqual (1 , 2 );
1034
- // AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
1035
- // + expected - actual
1036
- // - 1
1037
- // + 2
1044
+ // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
1045
+ //
1046
+ // 1 !== 2
1038
1047
1039
1048
assert .strictEqual (1 , 1 );
1040
1049
// OK
1041
1050
1042
- assert .strictEqual (1 , ' 1' );
1043
- // AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
1044
- // + expected - actual
1045
- // - 1
1046
- // + '1'
1051
+ assert .strictEqual (' Hello foobar' , ' Hello World!' );
1052
+ // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
1053
+ // + actual - expected
1054
+ //
1055
+ // + 'Hello foobar'
1056
+ // - 'Hello World!'
1057
+ // ^
1047
1058
```
1048
1059
1049
1060
If the values are not strictly equal, an ` AssertionError ` is thrown with a
@@ -1211,20 +1222,21 @@ function notThrowing() {}
1211
1222
assert .throws (throwingFirst, ' Second' );
1212
1223
// In the next example the message has no benefit over the message from the
1213
1224
// error and since it is not clear if the user intended to actually match
1214
- // against the error message, Node.js thrown an `ERR_AMBIGUOUS_ARGUMENT` error.
1225
+ // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.
1215
1226
assert .throws (throwingSecond, ' Second' );
1216
- // Throws an error:
1217
1227
// TypeError [ERR_AMBIGUOUS_ARGUMENT]
1218
1228
1219
1229
// The string is only used (as message) in case the function does not throw:
1220
1230
assert .throws (notThrowing, ' Second' );
1221
1231
// AssertionError [ERR_ASSERTION]: Missing expected exception: Second
1222
1232
1223
1233
// If it was intended to match for the error message do this instead:
1234
+ // It does not throw because the error messages match.
1224
1235
assert .throws (throwingSecond, / Second$ / );
1225
- // Does not throw because the error messages match.
1236
+
1237
+ // If the error message does not match, the error from within the function is
1238
+ // not caught.
1226
1239
assert .throws (throwingFirst, / Second$ / );
1227
- // Throws an error:
1228
1240
// Error: First
1229
1241
// at throwingFirst (repl:2:9)
1230
1242
```
0 commit comments