@@ -34,6 +34,12 @@ const { writeFileSync, unlinkSync } = require('fs');
34
34
const { inspect } = require ( 'util' ) ;
35
35
const a = assert ;
36
36
37
+ const colors = process . stdout . isTTY && process . stdout . getColorDepth ( ) > 1 ;
38
+ const start = 'Input A expected to deepStrictEqual input B:' ;
39
+ const actExp = colors ?
40
+ '\u001b[32m+ expected\u001b[39m \u001b[31m- actual\u001b[39m' :
41
+ '+ expected - actual' ;
42
+
37
43
assert . ok ( a . AssertionError . prototype instanceof Error ,
38
44
'a.AssertionError instanceof Error' ) ;
39
45
@@ -436,11 +442,6 @@ common.expectsError(
436
442
Error . stackTraceLimit = tmpLimit ;
437
443
438
444
// Test error diffs.
439
- const colors = process . stdout . isTTY && process . stdout . getColorDepth ( ) > 1 ;
440
- const start = 'Input A expected to deepStrictEqual input B:' ;
441
- const actExp = colors ?
442
- '\u001b[32m+ expected\u001b[39m \u001b[31m- actual\u001b[39m' :
443
- '+ expected - actual' ;
444
445
const plus = colors ? '\u001b[32m+\u001b[39m' : '+' ;
445
446
const minus = colors ? '\u001b[31m-\u001b[39m' : '-' ;
446
447
let message = [
@@ -765,24 +766,32 @@ common.expectsError(
765
766
errObj . code = 404 ;
766
767
assert . throws ( errFn , errObj ) ;
767
768
768
- errObj . code = '404' ;
769
- common . expectsError (
769
+ // Fail in case a expected property is undefined and not existent on the
770
+ // error.
771
+ errObj . foo = undefined ;
772
+ assert . throws (
770
773
( ) => assert . throws ( errFn , errObj ) ,
771
774
{
772
775
code : 'ERR_ASSERTION' ,
773
- type : assert . AssertionError ,
774
- message : 'code: expected \'404\', not 404'
776
+ name : 'AssertionError [ERR_ASSERTION]' ,
777
+ message : `${ start } \n${ actExp } \n\n` +
778
+ " Comparison {\n name: 'TypeError',\n" +
779
+ " message: 'Wrong value',\n- code: 404\n" +
780
+ '+ code: 404,\n+ foo: undefined\n }'
775
781
}
776
782
) ;
777
783
778
- errObj . code = 404 ;
779
- errObj . foo = 'bar ' ;
780
- common . expectsError (
784
+ // Show multiple wrong properties at the same time.
785
+ errObj . code = '404 ' ;
786
+ assert . throws (
781
787
( ) => assert . throws ( errFn , errObj ) ,
782
788
{
783
789
code : 'ERR_ASSERTION' ,
784
- type : assert . AssertionError ,
785
- message : 'foo: expected \'bar\', not undefined'
790
+ name : 'AssertionError [ERR_ASSERTION]' ,
791
+ message : `${ start } \n${ actExp } \n\n` +
792
+ " Comparison {\n name: 'TypeError',\n" +
793
+ " message: 'Wrong value',\n- code: 404\n" +
794
+ "+ code: '404',\n+ foo: undefined\n }"
786
795
}
787
796
) ;
788
797
@@ -806,20 +815,24 @@ common.expectsError(
806
815
) ;
807
816
808
817
assert . throws ( ( ) => { throw new Error ( 'e' ) ; } , new Error ( 'e' ) ) ;
809
- common . expectsError (
818
+ assert . throws (
810
819
( ) => assert . throws ( ( ) => { throw new TypeError ( 'e' ) ; } , new Error ( 'e' ) ) ,
811
820
{
812
- type : assert . AssertionError ,
821
+ name : ' AssertionError [ERR_ASSERTION]' ,
813
822
code : 'ERR_ASSERTION' ,
814
- message : "name: expected 'Error', not 'TypeError'"
823
+ message : `${ start } \n${ actExp } \n\n` +
824
+ " Comparison {\n- name: 'TypeError',\n+ name: 'Error'," +
825
+ "\n message: 'e'\n }"
815
826
}
816
827
) ;
817
- common . expectsError (
828
+ assert . throws (
818
829
( ) => assert . throws ( ( ) => { throw new Error ( 'foo' ) ; } , new Error ( '' ) ) ,
819
830
{
820
- type : assert . AssertionError ,
831
+ name : ' AssertionError [ERR_ASSERTION]' ,
821
832
code : 'ERR_ASSERTION' ,
822
- message : "message: expected '', not 'foo'"
833
+ message : `${ start } \n${ actExp } \n\n` +
834
+ " Comparison {\n name: 'Error',\n- message: 'foo'" +
835
+ "\n+ message: ''\n }"
823
836
}
824
837
) ;
825
838
0 commit comments