@@ -28,6 +28,7 @@ describe('Integration | sendReplayEvent', () => {
28
28
let mockTransportSend : MockTransportSend ;
29
29
let mockSendReplayRequest : MockInstance < any > ;
30
30
let domHandler : DomHandler ;
31
+ const onError : ( ) => void = vi . fn ( ) ;
31
32
const { record : mockRecord } = mockRrweb ( ) ;
32
33
33
34
beforeAll ( async ( ) => {
@@ -44,6 +45,7 @@ describe('Integration | sendReplayEvent', () => {
44
45
_experiments : {
45
46
captureExceptions : true ,
46
47
} ,
48
+ onError,
47
49
} ,
48
50
} ) ) ;
49
51
@@ -54,6 +56,7 @@ describe('Integration | sendReplayEvent', () => {
54
56
} ) ;
55
57
56
58
beforeEach ( ( ) => {
59
+ vi . clearAllMocks ( ) ;
57
60
vi . setSystemTime ( new Date ( BASE_TIMESTAMP ) ) ;
58
61
mockRecord . takeFullSnapshot . mockClear ( ) ;
59
62
mockTransportSend . mockClear ( ) ;
@@ -357,8 +360,9 @@ describe('Integration | sendReplayEvent', () => {
357
360
expect ( replay ) . not . toHaveLastSentReplay ( ) ;
358
361
} ) ;
359
362
360
- it ( 'fails to upload data and hits retry max and stops ' , async ( ) => {
363
+ it ( 'fails to upload data, hits retry max, stops, and calls `onError` with the error ' , async ( ) => {
361
364
const TEST_EVENT = getTestEventIncremental ( { timestamp : BASE_TIMESTAMP } ) ;
365
+ const ERROR = new Error ( 'Something bad happened' ) ;
362
366
363
367
const spyHandleException = vi . spyOn ( SentryCore , 'captureException' ) ;
364
368
@@ -369,7 +373,7 @@ describe('Integration | sendReplayEvent', () => {
369
373
370
374
// fail all requests
371
375
mockSendReplayRequest . mockImplementation ( async ( ) => {
372
- throw new Error ( 'Something bad happened' ) ;
376
+ throw ERROR ;
373
377
} ) ;
374
378
mockRecord . _emitter ( TEST_EVENT ) ;
375
379
@@ -406,6 +410,8 @@ describe('Integration | sendReplayEvent', () => {
406
410
// Replay has stopped, no session should exist
407
411
expect ( replay . session ) . toBe ( undefined ) ;
408
412
expect ( replay . isEnabled ( ) ) . toBe ( false ) ;
413
+ expect ( onError ) . toHaveBeenCalledTimes ( 5 ) ;
414
+ expect ( onError ) . toHaveBeenCalledWith ( ERROR ) ;
409
415
410
416
// Events are ignored now, because we stopped
411
417
mockRecord . _emitter ( TEST_EVENT ) ;
0 commit comments