@@ -899,6 +899,78 @@ test('.throws()', gather(t => {
899
899
formatted : / n u l l / ,
900
900
} ] ,
901
901
} ) ;
902
+
903
+ // Fails because the string in the message is incorrect
904
+ failsWith (
905
+ t ,
906
+ ( ) =>
907
+ assertions . throws (
908
+ ( ) => {
909
+ throw new Error ( 'error' ) ;
910
+ } ,
911
+ { message : 'my error' } ,
912
+ ) ,
913
+ {
914
+ assertion : 'throws' ,
915
+ message : '' ,
916
+ values : [
917
+ { label : 'Function threw unexpected exception:' , formatted : / e r r o r / } ,
918
+ { label : 'Expected message to equal:' , formatted : / m y e r r o r / } ,
919
+ ] ,
920
+ } ,
921
+ ) ;
922
+
923
+ passes ( t , ( ) => assertions . throws ( ( ) => {
924
+ throw new Error ( 'error' ) ;
925
+ } , { message : 'error' } ) ) ;
926
+
927
+ // Fails because the regular expression in the message is incorrect
928
+ failsWith (
929
+ t ,
930
+ ( ) =>
931
+ assertions . throws (
932
+ ( ) => {
933
+ throw new Error ( 'error' ) ;
934
+ } ,
935
+ { message : / m y e r r o r / } ,
936
+ ) ,
937
+ {
938
+ assertion : 'throws' ,
939
+ message : '' ,
940
+ values : [
941
+ { label : 'Function threw unexpected exception:' , formatted : / e r r o r / } ,
942
+ { label : 'Expected message to match:' , formatted : / m y e r r o r / } ,
943
+ ] ,
944
+ } ,
945
+ ) ;
946
+
947
+ passes ( t , ( ) => assertions . throws ( ( ) => {
948
+ throw new Error ( 'error' ) ;
949
+ } , { message : / e r r o r / } ) ) ;
950
+
951
+ // Fails because the function in the message returns false
952
+ failsWith (
953
+ t ,
954
+ ( ) =>
955
+ assertions . throws (
956
+ ( ) => {
957
+ throw new Error ( 'error' ) ;
958
+ } ,
959
+ { message : ( ) => false } ,
960
+ ) ,
961
+ {
962
+ assertion : 'throws' ,
963
+ message : '' ,
964
+ values : [
965
+ { label : 'Function threw unexpected exception:' , formatted : / e r r o r / } ,
966
+ { label : 'Expected message to return true:' , formatted : / F u n c t i o n / } ,
967
+ ] ,
968
+ } ,
969
+ ) ;
970
+
971
+ passes ( t , ( ) => assertions . throws ( ( ) => {
972
+ throw new Error ( 'error' ) ;
973
+ } , { message : ( ) => true } ) ) ;
902
974
} ) ) ;
903
975
904
976
test ( '.throws() returns the thrown error' , t => {
@@ -1066,7 +1138,7 @@ test('.throws() fails if passed a bad expectation', t => {
1066
1138
1067
1139
failsWith ( t , ( ) => assertions . throws ( ( ) => { } , { message : null } ) , {
1068
1140
assertion : 'throws' ,
1069
- message : 'The `message` property of the second argument to `t.throws()` must be a string or regular expression' ,
1141
+ message : 'The `message` property of the second argument to `t.throws()` must be a string, regular expression or a function ' ,
1070
1142
values : [ { label : 'Called with:' , formatted : / m e s s a g e : n u l l / } ] ,
1071
1143
} ) ;
1072
1144
@@ -1136,7 +1208,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => {
1136
1208
1137
1209
failsWith ( t , ( ) => assertions . throwsAsync ( ( ) => { } , { message : null } ) , {
1138
1210
assertion : 'throwsAsync' ,
1139
- message : 'The `message` property of the second argument to `t.throwsAsync()` must be a string or regular expression' ,
1211
+ message : 'The `message` property of the second argument to `t.throwsAsync()` must be a string, regular expression or a function ' ,
1140
1212
values : [ { label : 'Called with:' , formatted : / m e s s a g e : n u l l / } ] ,
1141
1213
} , { expectBoolean : false } ) ;
1142
1214
0 commit comments