@@ -28,6 +28,7 @@ describe('Integration | sendReplayEvent', () => {
2828 let mockTransportSend : MockTransportSend ;
2929 let mockSendReplayRequest : MockInstance < any > ;
3030 let domHandler : DomHandler ;
31+ const onError : ( ) => void = vi . fn ( ) ;
3132 const { record : mockRecord } = mockRrweb ( ) ;
3233
3334 beforeAll ( async ( ) => {
@@ -44,6 +45,7 @@ describe('Integration | sendReplayEvent', () => {
4445 _experiments : {
4546 captureExceptions : true ,
4647 } ,
48+ onError,
4749 } ,
4850 } ) ) ;
4951
@@ -54,6 +56,7 @@ describe('Integration | sendReplayEvent', () => {
5456 } ) ;
5557
5658 beforeEach ( ( ) => {
59+ vi . clearAllMocks ( ) ;
5760 vi . setSystemTime ( new Date ( BASE_TIMESTAMP ) ) ;
5861 mockRecord . takeFullSnapshot . mockClear ( ) ;
5962 mockTransportSend . mockClear ( ) ;
@@ -357,8 +360,9 @@ describe('Integration | sendReplayEvent', () => {
357360 expect ( replay ) . not . toHaveLastSentReplay ( ) ;
358361 } ) ;
359362
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 ( ) => {
361364 const TEST_EVENT = getTestEventIncremental ( { timestamp : BASE_TIMESTAMP } ) ;
365+ const ERROR = new Error ( 'Something bad happened' ) ;
362366
363367 const spyHandleException = vi . spyOn ( SentryCore , 'captureException' ) ;
364368
@@ -369,7 +373,7 @@ describe('Integration | sendReplayEvent', () => {
369373
370374 // fail all requests
371375 mockSendReplayRequest . mockImplementation ( async ( ) => {
372- throw new Error ( 'Something bad happened' ) ;
376+ throw ERROR ;
373377 } ) ;
374378 mockRecord . _emitter ( TEST_EVENT ) ;
375379
@@ -406,6 +410,8 @@ describe('Integration | sendReplayEvent', () => {
406410 // Replay has stopped, no session should exist
407411 expect ( replay . session ) . toBe ( undefined ) ;
408412 expect ( replay . isEnabled ( ) ) . toBe ( false ) ;
413+ expect ( onError ) . toHaveBeenCalledTimes ( 5 ) ;
414+ expect ( onError ) . toHaveBeenCalledWith ( ERROR ) ;
409415
410416 // Events are ignored now, because we stopped
411417 mockRecord . _emitter ( TEST_EVENT ) ;
0 commit comments