@@ -888,31 +888,33 @@ describe('BaseClient', () => {
888
888
} ) ;
889
889
890
890
test ( 'calls `beforeSend` and uses original event without any changes' , ( ) => {
891
- expect . assertions ( 1 ) ;
891
+ expect . assertions ( 2 ) ;
892
892
893
893
const beforeSend = jest . fn ( event => event ) ;
894
894
const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSend } ) ;
895
895
const client = new TestClient ( options ) ;
896
896
897
897
client . captureEvent ( { message : 'hello' } ) ;
898
898
899
+ expect ( beforeSend ) . toHaveBeenCalled ( ) ;
899
900
expect ( TestClient . instance ! . event ! . message ) . toEqual ( 'hello' ) ;
900
901
} ) ;
901
902
902
903
test ( 'calls `beforeSendTransaction` and uses original event without any changes' , ( ) => {
903
- expect . assertions ( 1 ) ;
904
+ expect . assertions ( 2 ) ;
904
905
905
906
const beforeSendTransaction = jest . fn ( event => event ) ;
906
907
const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendTransaction } ) ;
907
908
const client = new TestClient ( options ) ;
908
909
909
910
client . captureEvent ( { transaction : '/dogs/are/great' , type : 'transaction' } ) ;
910
911
912
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
911
913
expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/dogs/are/great' ) ;
912
914
} ) ;
913
915
914
916
test ( 'calls `beforeSend` and uses the modified event' , ( ) => {
915
- expect . assertions ( 1 ) ;
917
+ expect . assertions ( 2 ) ;
916
918
917
919
const beforeSend = jest . fn ( event => {
918
920
event . message = 'changed1' ;
@@ -923,11 +925,12 @@ describe('BaseClient', () => {
923
925
924
926
client . captureEvent ( { message : 'hello' } ) ;
925
927
928
+ expect ( beforeSend ) . toHaveBeenCalled ( ) ;
926
929
expect ( TestClient . instance ! . event ! . message ) . toEqual ( 'changed1' ) ;
927
930
} ) ;
928
931
929
932
test ( 'calls `beforeSendTransaction` and uses the modified event' , ( ) => {
930
- expect . assertions ( 1 ) ;
933
+ expect . assertions ( 2 ) ;
931
934
932
935
const beforeSendTransaction = jest . fn ( event => {
933
936
event . transaction = '/adopt/dont/shop' ;
@@ -938,11 +941,12 @@ describe('BaseClient', () => {
938
941
939
942
client . captureEvent ( { transaction : '/dogs/are/great' , type : 'transaction' } ) ;
940
943
944
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
941
945
expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/adopt/dont/shop' ) ;
942
946
} ) ;
943
947
944
948
test ( 'calls `beforeSend` and discards the event' , ( ) => {
945
- expect . assertions ( 3 ) ;
949
+ expect . assertions ( 4 ) ;
946
950
947
951
const beforeSend = jest . fn ( ( ) => null ) ;
948
952
const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSend } ) ;
@@ -952,6 +956,7 @@ describe('BaseClient', () => {
952
956
953
957
client . captureEvent ( { message : 'hello' } ) ;
954
958
959
+ expect ( beforeSend ) . toHaveBeenCalled ( ) ;
955
960
expect ( TestClient . instance ! . event ) . toBeUndefined ( ) ;
956
961
// This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
957
962
// error, but because `beforeSend` returned `null`
@@ -960,7 +965,7 @@ describe('BaseClient', () => {
960
965
} ) ;
961
966
962
967
test ( 'calls `beforeSendTransaction` and discards the event' , ( ) => {
963
- expect . assertions ( 3 ) ;
968
+ expect . assertions ( 4 ) ;
964
969
965
970
const beforeSendTransaction = jest . fn ( ( ) => null ) ;
966
971
const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendTransaction } ) ;
@@ -970,6 +975,7 @@ describe('BaseClient', () => {
970
975
971
976
client . captureEvent ( { transaction : '/dogs/are/great' , type : 'transaction' } ) ;
972
977
978
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
973
979
expect ( TestClient . instance ! . event ) . toBeUndefined ( ) ;
974
980
// This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
975
981
// error, but because `beforeSendTransaction` returned `null`
@@ -979,7 +985,7 @@ describe('BaseClient', () => {
979
985
980
986
test ( 'calls `beforeSend` and logs info about invalid return value' , ( ) => {
981
987
const invalidValues = [ undefined , false , true , [ ] , 1 ] ;
982
- expect . assertions ( invalidValues . length * 2 ) ;
988
+ expect . assertions ( invalidValues . length * 3 ) ;
983
989
984
990
for ( const val of invalidValues ) {
985
991
const beforeSend = jest . fn ( ( ) => val ) ;
@@ -990,14 +996,15 @@ describe('BaseClient', () => {
990
996
991
997
client . captureEvent ( { message : 'hello' } ) ;
992
998
999
+ expect ( beforeSend ) . toHaveBeenCalled ( ) ;
993
1000
expect ( TestClient . instance ! . event ) . toBeUndefined ( ) ;
994
1001
expect ( loggerWarnSpy ) . toBeCalledWith ( new SentryError ( '`beforeSend` must return `null` or a valid event.' ) ) ;
995
1002
}
996
1003
} ) ;
997
1004
998
1005
test ( 'calls `beforeSendTransaction` and logs info about invalid return value' , ( ) => {
999
1006
const invalidValues = [ undefined , false , true , [ ] , 1 ] ;
1000
- expect . assertions ( invalidValues . length * 2 ) ;
1007
+ expect . assertions ( invalidValues . length * 3 ) ;
1001
1008
1002
1009
for ( const val of invalidValues ) {
1003
1010
const beforeSendTransaction = jest . fn ( ( ) => val ) ;
@@ -1008,6 +1015,7 @@ describe('BaseClient', () => {
1008
1015
1009
1016
client . captureEvent ( { transaction : '/dogs/are/great' , type : 'transaction' } ) ;
1010
1017
1018
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
1011
1019
expect ( TestClient . instance ! . event ) . toBeUndefined ( ) ;
1012
1020
expect ( loggerWarnSpy ) . toBeCalledWith (
1013
1021
new SentryError ( '`beforeSendTransaction` must return `null` or a valid event.' ) ,
@@ -1017,7 +1025,7 @@ describe('BaseClient', () => {
1017
1025
1018
1026
test ( 'calls async `beforeSend` and uses original event without any changes' , done => {
1019
1027
jest . useFakeTimers ( ) ;
1020
- expect . assertions ( 1 ) ;
1028
+ expect . assertions ( 2 ) ;
1021
1029
1022
1030
const beforeSend = jest . fn (
1023
1031
async event =>
@@ -1034,6 +1042,7 @@ describe('BaseClient', () => {
1034
1042
jest . runOnlyPendingTimers ( ) ;
1035
1043
1036
1044
TestClient . sendEventCalled = ( event : Event ) => {
1045
+ expect ( beforeSend ) . toHaveBeenCalled ( ) ;
1037
1046
expect ( event . message ) . toEqual ( 'hello' ) ;
1038
1047
} ;
1039
1048
@@ -1046,7 +1055,7 @@ describe('BaseClient', () => {
1046
1055
1047
1056
test ( 'calls async `beforeSendTransaction` and uses original event without any changes' , done => {
1048
1057
jest . useFakeTimers ( ) ;
1049
- expect . assertions ( 1 ) ;
1058
+ expect . assertions ( 2 ) ;
1050
1059
1051
1060
const beforeSendTransaction = jest . fn (
1052
1061
async event =>
@@ -1063,6 +1072,7 @@ describe('BaseClient', () => {
1063
1072
jest . runOnlyPendingTimers ( ) ;
1064
1073
1065
1074
TestClient . sendEventCalled = ( event : Event ) => {
1075
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
1066
1076
expect ( event . transaction ) . toBe ( '/dogs/are/great' ) ;
1067
1077
} ;
1068
1078
@@ -1075,7 +1085,7 @@ describe('BaseClient', () => {
1075
1085
1076
1086
test ( 'calls async `beforeSend` and uses the modified event' , done => {
1077
1087
jest . useFakeTimers ( ) ;
1078
- expect . assertions ( 1 ) ;
1088
+ expect . assertions ( 2 ) ;
1079
1089
1080
1090
const beforeSend = jest . fn ( async event => {
1081
1091
event . message = 'changed2' ;
@@ -1092,6 +1102,7 @@ describe('BaseClient', () => {
1092
1102
jest . runOnlyPendingTimers ( ) ;
1093
1103
1094
1104
TestClient . sendEventCalled = ( event : Event ) => {
1105
+ expect ( beforeSend ) . toHaveBeenCalled ( ) ;
1095
1106
expect ( event . message ) . toEqual ( 'changed2' ) ;
1096
1107
} ;
1097
1108
@@ -1104,7 +1115,7 @@ describe('BaseClient', () => {
1104
1115
1105
1116
test ( 'calls async `beforeSendTransaction` and uses the modified event' , done => {
1106
1117
jest . useFakeTimers ( ) ;
1107
- expect . assertions ( 1 ) ;
1118
+ expect . assertions ( 2 ) ;
1108
1119
1109
1120
const beforeSendTransaction = jest . fn ( async event => {
1110
1121
event . transaction = '/adopt/dont/shop' ;
@@ -1121,6 +1132,7 @@ describe('BaseClient', () => {
1121
1132
jest . runOnlyPendingTimers ( ) ;
1122
1133
1123
1134
TestClient . sendEventCalled = ( event : Event ) => {
1135
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
1124
1136
expect ( event . transaction ) . toBe ( '/adopt/dont/shop' ) ;
1125
1137
} ;
1126
1138
@@ -1133,7 +1145,7 @@ describe('BaseClient', () => {
1133
1145
1134
1146
test ( 'calls async `beforeSend` and discards the event' , ( ) => {
1135
1147
jest . useFakeTimers ( ) ;
1136
- expect . assertions ( 1 ) ;
1148
+ expect . assertions ( 2 ) ;
1137
1149
1138
1150
const beforeSend = jest . fn (
1139
1151
async ( ) =>
@@ -1149,12 +1161,13 @@ describe('BaseClient', () => {
1149
1161
client . captureEvent ( { message : 'hello' } ) ;
1150
1162
jest . runAllTimers ( ) ;
1151
1163
1164
+ expect ( beforeSend ) . toHaveBeenCalled ( ) ;
1152
1165
expect ( TestClient . instance ! . event ) . toBeUndefined ( ) ;
1153
1166
} ) ;
1154
1167
1155
1168
test ( 'calls async `beforeSendTransaction` and discards the event' , ( ) => {
1156
1169
jest . useFakeTimers ( ) ;
1157
- expect . assertions ( 1 ) ;
1170
+ expect . assertions ( 2 ) ;
1158
1171
1159
1172
const beforeSendTransaction = jest . fn (
1160
1173
async ( ) =>
@@ -1170,24 +1183,26 @@ describe('BaseClient', () => {
1170
1183
client . captureEvent ( { transaction : '/dogs/are/great' , type : 'transaction' } ) ;
1171
1184
jest . runAllTimers ( ) ;
1172
1185
1186
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
1173
1187
expect ( TestClient . instance ! . event ) . toBeUndefined ( ) ;
1174
1188
} ) ;
1175
1189
1176
1190
test ( '`beforeSend` gets access to a hint as a second argument' , ( ) => {
1177
- expect . assertions ( 2 ) ;
1191
+ expect . assertions ( 3 ) ;
1178
1192
1179
1193
const beforeSend = jest . fn ( ( event , hint ) => ( { ...event , data : hint . data } ) ) ;
1180
1194
const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSend } ) ;
1181
1195
const client = new TestClient ( options ) ;
1182
1196
1183
1197
client . captureEvent ( { message : 'hello' } , { data : 'someRandomThing' } ) ;
1184
1198
1199
+ expect ( beforeSend ) . toHaveBeenCalledWith ( expect . any ( Object ) , expect . objectContaining ( { data : 'someRandomThing' } ) ) ;
1185
1200
expect ( TestClient . instance ! . event ! . message ) . toEqual ( 'hello' ) ;
1186
1201
expect ( ( TestClient . instance ! . event ! as any ) . data ) . toEqual ( 'someRandomThing' ) ;
1187
1202
} ) ;
1188
1203
1189
1204
test ( '`beforeSendTransaction` gets access to a hint as a second argument' , ( ) => {
1190
- expect . assertions ( 2 ) ;
1205
+ expect . assertions ( 3 ) ;
1191
1206
1192
1207
const beforeSendTransaction = jest . fn ( ( event , hint ) => ( { ...event , data : hint . data } ) ) ;
1193
1208
const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendTransaction } ) ;
@@ -1198,45 +1213,50 @@ describe('BaseClient', () => {
1198
1213
{ data : { dogs : 'yes' , cats : 'maybe' } } ,
1199
1214
) ;
1200
1215
1216
+ expect ( beforeSendTransaction ) . toHaveBeenCalledWith (
1217
+ expect . any ( Object ) ,
1218
+ expect . objectContaining ( { data : { dogs : 'yes' , cats : 'maybe' } } ) ,
1219
+ ) ;
1201
1220
expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/dogs/are/great' ) ;
1202
1221
expect ( ( TestClient . instance ! . event ! as any ) . data ) . toEqual ( { dogs : 'yes' , cats : 'maybe' } ) ;
1203
1222
} ) ;
1204
1223
1205
1224
test ( '`beforeSend` records dropped events' , ( ) => {
1206
- expect . assertions ( 1 ) ;
1225
+ expect . assertions ( 2 ) ;
1207
1226
1227
+ const beforeSend = jest . fn ( ( ) => null ) ;
1208
1228
const client = new TestClient (
1209
1229
getDefaultTestClientOptions ( {
1210
1230
dsn : PUBLIC_DSN ,
1211
- beforeSend ( ) {
1212
- return null ;
1213
- } ,
1231
+ beforeSend,
1214
1232
} ) ,
1215
1233
) ;
1216
1234
1217
1235
const recordLostEventSpy = jest . spyOn ( client , 'recordDroppedEvent' ) ;
1218
1236
1219
1237
client . captureEvent ( { message : 'hello' } , { } ) ;
1220
1238
1239
+ expect ( beforeSend ) . toHaveBeenCalled ( ) ;
1221
1240
expect ( recordLostEventSpy ) . toHaveBeenCalledWith ( 'before_send' , 'error' ) ;
1222
1241
} ) ;
1223
1242
1224
1243
test ( '`beforeSendTransaction` records dropped events' , ( ) => {
1225
- expect . assertions ( 1 ) ;
1244
+ expect . assertions ( 2 ) ;
1245
+
1246
+ const beforeSendTransaction = jest . fn ( ( ) => null ) ;
1226
1247
1227
1248
const client = new TestClient (
1228
1249
getDefaultTestClientOptions ( {
1229
1250
dsn : PUBLIC_DSN ,
1230
- beforeSendTransaction ( ) {
1231
- return null ;
1232
- } ,
1251
+ beforeSendTransaction,
1233
1252
} ) ,
1234
1253
) ;
1235
1254
1236
1255
const recordLostEventSpy = jest . spyOn ( client , 'recordDroppedEvent' ) ;
1237
1256
1238
1257
client . captureEvent ( { transaction : '/dogs/are/great' , type : 'transaction' } ) ;
1239
1258
1259
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
1240
1260
expect ( recordLostEventSpy ) . toHaveBeenCalledWith ( 'before_send' , 'transaction' ) ;
1241
1261
} ) ;
1242
1262
@@ -1361,6 +1381,7 @@ describe('BaseClient', () => {
1361
1381
} ,
1362
1382
} ) ;
1363
1383
1384
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
1364
1385
expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/adopt/dont/shop' ) ;
1365
1386
expect ( TestClient . instance ! . event ! . transaction_info ) . toEqual ( {
1366
1387
source : 'custom' ,
0 commit comments