@@ -108,15 +108,15 @@ Example error diff:
108108const assert = require (' assert' ).strict ;
109109
110110assert .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
113113//
114114// [
115115// [
116116// ...
117117// 2,
118- // - 3
119- // + '3'
118+ // + 3
119+ // - '3'
120120// ],
121121// ...
122122// 5
@@ -315,11 +315,12 @@ const assert = require('assert').strict;
315315
316316// This fails because 1 !== '1'.
317317assert .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+ //
320321// {
321- // - a: 1
322- // + a: '1'
322+ // + a: 1
323+ // - a: '1'
323324// }
324325
325326// The following objects don't have own properties
@@ -330,27 +331,30 @@ Object.setPrototypeOf(fakeDate, Date.prototype);
330331
331332// Different [[Prototype]]:
332333assert .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 {}
337339
338340// Different type tags:
339341assert .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 {}
344347
345348assert .deepStrictEqual (NaN , NaN );
346349// OK, because of the SameValue comparison
347350
348351// Different unwrapped numbers:
349352assert .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]
354358
355359assert .deepStrictEqual (new String (' foo' ), Object (' foo' ));
356360// OK because the object and the string are identical when unwrapped.
@@ -360,17 +364,20 @@ assert.deepStrictEqual(-0, -0);
360364
361365// Different zeros using the SameValue Comparison:
362366assert .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
367372
368373const symbol1 = Symbol ();
369374const symbol2 = Symbol ();
370375assert .deepStrictEqual ({ [symbol1]: 1 }, { [symbol1]: 1 });
371376// OK, because it is the same symbol on both objects.
377+
372378assert .deepStrictEqual ({ [symbol1]: 1 }, { [symbol2]: 1 });
373- // AssertionError [ERR_ASSERTION]: Input objects not identical:
379+ // AssertionError [ERR_ASSERTION]: Inputs identical but not reference equal:
380+ //
374381// {
375382// [Symbol()]: 1
376383// }
@@ -385,12 +392,13 @@ assert.deepStrictEqual(weakMap1, weakMap2);
385392
386393// Fails because weakMap3 has a property that weakMap1 does not contain:
387394assert .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+ //
390398// WeakMap {
391- // - [items unknown]
392- // + [items unknown],
393- // + unequal: true
399+ // + [items unknown]
400+ // - [items unknown],
401+ // - unequal: true
394402// }
395403```
396404
@@ -875,7 +883,9 @@ assert.notStrictEqual(1, 2);
875883// OK
876884
877885assert .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
879889
880890assert .notStrictEqual (1 , ' 1' );
881891// OK
@@ -1031,19 +1041,20 @@ determined by the [SameValue Comparison][].
10311041const assert = require (' assert' ).strict ;
10321042
10331043assert .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
10381047
10391048assert .strictEqual (1 , 1 );
10401049// OK
10411050
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+ // ^
10471058```
10481059
10491060If the values are not strictly equal, an ` AssertionError ` is thrown with a
@@ -1211,20 +1222,21 @@ function notThrowing() {}
12111222assert .throws (throwingFirst, ' Second' );
12121223// In the next example the message has no benefit over the message from the
12131224// 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.
12151226assert .throws (throwingSecond, ' Second' );
1216- // Throws an error:
12171227// TypeError [ERR_AMBIGUOUS_ARGUMENT]
12181228
12191229// The string is only used (as message) in case the function does not throw:
12201230assert .throws (notThrowing, ' Second' );
12211231// AssertionError [ERR_ASSERTION]: Missing expected exception: Second
12221232
12231233// If it was intended to match for the error message do this instead:
1234+ // It does not throw because the error messages match.
12241235assert .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.
12261239assert .throws (throwingFirst, / Second$ / );
1227- // Throws an error:
12281240// Error: First
12291241// at throwingFirst (repl:2:9)
12301242```
0 commit comments