@@ -27,13 +27,6 @@ describe('Hub', () => {
27
27
expect ( hub . getStack ( ) ) . toHaveLength ( 1 ) ;
28
28
} ) ;
29
29
30
- test . skip ( "don't invoke client sync with wrong func" , ( ) => {
31
- const hub = new Hub ( clientFn ) ;
32
- // @ts -ignore we want to able to call private method
33
- hub . _invokeClient ( 'funca' , true ) ;
34
- expect ( clientFn ) . not . toHaveBeenCalled ( ) ;
35
- } ) ;
36
-
37
30
test ( 'isOlderThan' , ( ) => {
38
31
const hub = new Hub ( ) ;
39
32
expect ( hub . isOlderThan ( 0 ) ) . toBeFalsy ( ) ;
@@ -194,113 +187,104 @@ describe('Hub', () => {
194
187
} ) ;
195
188
196
189
describe ( 'captureException' , ( ) => {
197
- test . skip ( 'simple' , ( ) => {
198
- const hub = new Hub ( ) ;
199
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
190
+ const mockClient : any = { captureException : jest . fn ( ) } ;
191
+ beforeEach ( ( ) => {
192
+ mockClient . captureException . mockClear ( ) ;
193
+ } ) ;
194
+
195
+ test ( 'simple' , ( ) => {
196
+ const hub = new Hub ( mockClient ) ;
200
197
hub . captureException ( 'a' ) ;
201
- expect ( spy ) . toHaveBeenCalled ( ) ;
202
- expect ( spy . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'captureException' ) ;
203
- expect ( spy . mock . calls [ 0 ] [ 1 ] ) . toBe ( 'a' ) ;
198
+ expect ( mockClient . captureException ) . toHaveBeenCalled ( ) ;
199
+ expect ( mockClient . captureException . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'a' ) ;
204
200
} ) ;
205
201
206
- test . skip ( 'should set event_id in hint' , ( ) => {
207
- const hub = new Hub ( ) ;
208
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
202
+ test ( 'should set event_id in hint' , ( ) => {
203
+ const hub = new Hub ( mockClient ) ;
209
204
hub . captureException ( 'a' ) ;
210
- // @ts -ignore Says mock object is type unknown
211
- expect ( spy . mock . calls [ 0 ] [ 2 ] . event_id ) . toBeTruthy ( ) ;
205
+ expect ( mockClient . captureException . mock . calls [ 0 ] [ 1 ] . event_id ) . toBeTruthy ( ) ;
212
206
} ) ;
213
207
214
- test . skip ( 'should generate hint if not provided in the call' , ( ) => {
215
- const hub = new Hub ( ) ;
216
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
208
+ test ( 'should generate hint if not provided in the call' , ( ) => {
209
+ const hub = new Hub ( mockClient ) ;
217
210
const ex = new Error ( 'foo' ) ;
218
211
hub . captureException ( ex ) ;
219
- // @ts -ignore Says mock object is type unknown
220
- expect ( spy . mock . calls [ 0 ] [ 2 ] . originalException ) . toBe ( ex ) ;
221
- // @ts -ignore Says mock object is type unknown
222
- expect ( spy . mock . calls [ 0 ] [ 2 ] . syntheticException ) . toBeInstanceOf ( Error ) ;
223
- // @ts -ignore Says mock object is type unknown
224
- expect ( spy . mock . calls [ 0 ] [ 2 ] . syntheticException . message ) . toBe ( 'Sentry syntheticException' ) ;
212
+ expect ( mockClient . captureException . mock . calls [ 0 ] [ 1 ] . originalException ) . toBe ( ex ) ;
213
+ expect ( mockClient . captureException . mock . calls [ 0 ] [ 1 ] . syntheticException ) . toBeInstanceOf ( Error ) ;
214
+ expect ( mockClient . captureException . mock . calls [ 0 ] [ 1 ] . syntheticException . message ) . toBe ( 'Sentry syntheticException' ) ;
225
215
} ) ;
226
216
} ) ;
227
217
228
218
describe ( 'captureMessage' , ( ) => {
229
- test . skip ( 'simple' , ( ) => {
230
- const hub = new Hub ( ) ;
231
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
219
+ const mockClient : any = { captureMessage : jest . fn ( ) } ;
220
+ beforeEach ( ( ) => {
221
+ mockClient . captureMessage . mockClear ( ) ;
222
+ } ) ;
223
+
224
+ test ( 'simple' , ( ) => {
225
+ const hub = new Hub ( mockClient ) ;
232
226
hub . captureMessage ( 'a' ) ;
233
- expect ( spy ) . toHaveBeenCalled ( ) ;
234
- expect ( spy . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'captureMessage' ) ;
235
- expect ( spy . mock . calls [ 0 ] [ 1 ] ) . toBe ( 'a' ) ;
227
+ expect ( mockClient . captureMessage ) . toHaveBeenCalled ( ) ;
228
+ expect ( mockClient . captureMessage . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'a' ) ;
236
229
} ) ;
237
230
238
- test . skip ( 'should set event_id in hint' , ( ) => {
239
- const hub = new Hub ( ) ;
240
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
231
+ test ( 'should set event_id in hint' , ( ) => {
232
+ const hub = new Hub ( mockClient ) ;
241
233
hub . captureMessage ( 'a' ) ;
242
- // @ts -ignore Says mock object is type unknown
243
- expect ( spy . mock . calls [ 0 ] [ 3 ] . event_id ) . toBeTruthy ( ) ;
234
+ expect ( mockClient . captureMessage . mock . calls [ 0 ] [ 2 ] . event_id ) . toBeTruthy ( ) ;
244
235
} ) ;
245
236
246
- test . skip ( 'should generate hint if not provided in the call' , ( ) => {
247
- const hub = new Hub ( ) ;
248
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
237
+ test ( 'should generate hint if not provided in the call' , ( ) => {
238
+ const hub = new Hub ( mockClient ) ;
249
239
hub . captureMessage ( 'foo' ) ;
250
- // @ts -ignore Says mock object is type unknown
251
- expect ( spy . mock . calls [ 0 ] [ 3 ] . originalException ) . toBe ( 'foo' ) ;
252
- // @ts -ignore Says mock object is type unknown
253
- expect ( spy . mock . calls [ 0 ] [ 3 ] . syntheticException ) . toBeInstanceOf ( Error ) ;
254
- // @ts -ignore Says mock object is type unknown
255
- expect ( spy . mock . calls [ 0 ] [ 3 ] . syntheticException . message ) . toBe ( 'foo' ) ;
240
+ expect ( mockClient . captureMessage . mock . calls [ 0 ] [ 2 ] . originalException ) . toBe ( 'foo' ) ;
241
+ expect ( mockClient . captureMessage . mock . calls [ 0 ] [ 2 ] . syntheticException ) . toBeInstanceOf ( Error ) ;
242
+ expect ( mockClient . captureMessage . mock . calls [ 0 ] [ 2 ] . syntheticException . message ) . toBe ( 'foo' ) ;
256
243
} ) ;
257
244
} ) ;
258
245
259
246
describe ( 'captureEvent' , ( ) => {
260
- test . skip ( 'simple' , ( ) => {
247
+ const mockClient : any = { captureEvent : jest . fn ( ) } ;
248
+ beforeEach ( ( ) => {
249
+ mockClient . captureEvent . mockClear ( ) ;
250
+ } ) ;
251
+
252
+ test ( 'simple' , ( ) => {
261
253
const event : Event = {
262
254
extra : { b : 3 } ,
263
255
} ;
264
- const hub = new Hub ( ) ;
265
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
256
+ const hub = new Hub ( mockClient ) ;
266
257
hub . captureEvent ( event ) ;
267
- expect ( spy ) . toHaveBeenCalled ( ) ;
268
- expect ( spy . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'captureEvent' ) ;
269
- expect ( spy . mock . calls [ 0 ] [ 1 ] ) . toBe ( event ) ;
258
+ expect ( mockClient . captureEvent ) . toHaveBeenCalled ( ) ;
259
+ expect ( mockClient . captureEvent . mock . calls [ 0 ] [ 0 ] ) . toBe ( event ) ;
270
260
} ) ;
271
261
272
- test . skip ( 'should set event_id in hint' , ( ) => {
262
+ test ( 'should set event_id in hint' , ( ) => {
273
263
const event : Event = {
274
264
extra : { b : 3 } ,
275
265
} ;
276
- const hub = new Hub ( ) ;
277
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
266
+ const hub = new Hub ( mockClient ) ;
278
267
hub . captureEvent ( event ) ;
279
- // @ts -ignore Says mock object is type unknown
280
- expect ( spy . mock . calls [ 0 ] [ 2 ] . event_id ) . toBeTruthy ( ) ;
268
+ expect ( mockClient . captureEvent . mock . calls [ 0 ] [ 1 ] . event_id ) . toBeTruthy ( ) ;
281
269
} ) ;
282
270
283
- test . skip ( 'sets lastEventId' , ( ) => {
271
+ test ( 'sets lastEventId' , ( ) => {
284
272
const event : Event = {
285
273
extra : { b : 3 } ,
286
274
} ;
287
- const hub = new Hub ( ) ;
288
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
275
+ const hub = new Hub ( mockClient ) ;
289
276
hub . captureEvent ( event ) ;
290
- // @ts -ignore Says mock object is type unknown
291
- expect ( spy . mock . calls [ 0 ] [ 2 ] . event_id ) . toEqual ( hub . lastEventId ( ) ) ;
277
+ expect ( mockClient . captureEvent . mock . calls [ 0 ] [ 1 ] . event_id ) . toEqual ( hub . lastEventId ( ) ) ;
292
278
} ) ;
293
279
294
- test . skip ( 'transactions do not set lastEventId' , ( ) => {
280
+ test ( 'transactions do not set lastEventId' , ( ) => {
295
281
const event : Event = {
296
282
extra : { b : 3 } ,
297
283
type : 'transaction' ,
298
284
} ;
299
- const hub = new Hub ( ) ;
300
- const spy = jest . spyOn ( hub as any , '_invokeClient' ) ;
285
+ const hub = new Hub ( mockClient ) ;
301
286
hub . captureEvent ( event ) ;
302
- // @ts -ignore Says mock object is type unknown
303
- expect ( spy . mock . calls [ 0 ] [ 2 ] . event_id ) . not . toEqual ( hub . lastEventId ( ) ) ;
287
+ expect ( mockClient . captureEvent . mock . calls [ 0 ] [ 1 ] . event_id ) . not . toEqual ( hub . lastEventId ( ) ) ;
304
288
} ) ;
305
289
} ) ;
306
290
0 commit comments