@@ -39,16 +39,6 @@ assert.ok(a.AssertionError.prototype instanceof Error,
39
39
40
40
assert . throws ( makeBlock ( a , false ) , a . AssertionError , 'ok(false)' ) ;
41
41
42
- // Using a object as second arg results in a failure
43
- assert . throws (
44
- ( ) => { assert . throws ( ( ) => { throw new Error ( ) ; } , { foo : 'bar' } ) ; } ,
45
- common . expectsError ( {
46
- type : TypeError ,
47
- message : 'expected.test is not a function'
48
- } )
49
- ) ;
50
-
51
-
52
42
assert . doesNotThrow ( makeBlock ( a , true ) , a . AssertionError , 'ok(true)' ) ;
53
43
54
44
assert . doesNotThrow ( makeBlock ( a , 'test' , 'ok(\'test\')' ) ) ;
@@ -784,3 +774,79 @@ common.expectsError(
784
774
'Received type string'
785
775
}
786
776
) ;
777
+
778
+ {
779
+ const errFn = ( ) => {
780
+ const err = new TypeError ( 'Wrong value' ) ;
781
+ err . code = 404 ;
782
+ throw err ;
783
+ } ;
784
+ const errObj = {
785
+ name : 'TypeError' ,
786
+ message : 'Wrong value'
787
+ } ;
788
+ assert . throws ( errFn , errObj ) ;
789
+
790
+ errObj . code = 404 ;
791
+ assert . throws ( errFn , errObj ) ;
792
+
793
+ errObj . code = '404' ;
794
+ common . expectsError (
795
+ // eslint-disable-next-line no-restricted-syntax
796
+ ( ) => assert . throws ( errFn , errObj ) ,
797
+ {
798
+ code : 'ERR_ASSERTION' ,
799
+ type : assert . AssertionError ,
800
+ message : 'code: expected \'404\', not 404'
801
+ }
802
+ ) ;
803
+
804
+ errObj . code = 404 ;
805
+ errObj . foo = 'bar' ;
806
+ common . expectsError (
807
+ // eslint-disable-next-line no-restricted-syntax
808
+ ( ) => assert . throws ( errFn , errObj ) ,
809
+ {
810
+ code : 'ERR_ASSERTION' ,
811
+ type : assert . AssertionError ,
812
+ message : 'foo: expected \'bar\', not undefined'
813
+ }
814
+ ) ;
815
+
816
+ common . expectsError (
817
+ ( ) => assert . throws ( ( ) => { throw new Error ( ) ; } , { foo : 'bar' } , 'foobar' ) ,
818
+ {
819
+ type : assert . AssertionError ,
820
+ code : 'ERR_ASSERTION' ,
821
+ message : 'foobar'
822
+ }
823
+ ) ;
824
+
825
+ common . expectsError (
826
+ ( ) => assert . doesNotThrow ( ( ) => { throw new Error ( ) ; } , { foo : 'bar' } ) ,
827
+ {
828
+ type : TypeError ,
829
+ code : 'ERR_INVALID_ARG_TYPE' ,
830
+ message : 'The "expected" argument must be one of type Function or ' +
831
+ 'RegExp. Received type object'
832
+ }
833
+ ) ;
834
+
835
+ assert . throws ( ( ) => { throw new Error ( 'e' ) ; } , new Error ( 'e' ) ) ;
836
+ common . expectsError (
837
+ ( ) => assert . throws ( ( ) => { throw new TypeError ( 'e' ) ; } , new Error ( 'e' ) ) ,
838
+ {
839
+ type : assert . AssertionError ,
840
+ code : 'ERR_ASSERTION' ,
841
+ message : "name: expected 'Error', not 'TypeError'"
842
+ }
843
+ ) ;
844
+ common . expectsError (
845
+ ( ) => assert . throws ( ( ) => { throw new Error ( 'foo' ) ; } , new Error ( '' ) ) ,
846
+ {
847
+ type : assert . AssertionError ,
848
+ code : 'ERR_ASSERTION' ,
849
+ message : "message: expected '', not 'foo'"
850
+ }
851
+ ) ;
852
+ }
0 commit comments