11import '../mocks/mockXhrNetworkInterceptor' ;
22import { NativeModules , Platform } from 'react-native' ;
33import Instabug from '../../src' ;
4+ import InstabugUtils from '../../src/utils/InstabugUtils' ;
5+ import IBGEventEmitter from '../../src/utils/IBGEventEmitter' ;
6+ import IBGConstants from '../../src/utils/InstabugConstants' ;
47
58const { Instabug : NativeInstabug } = NativeModules ;
69
@@ -26,20 +29,21 @@ describe('Test global error handler', () => {
2629 expect ( NativeInstabug . sendJSCrash ) . toHaveBeenCalledWith ( expected ) ;
2730 } ) ;
2831
29- // it('should emit event IBGSendUnhandledJSCrash when platform is android and onReportSubmitHandler is set', (done) => {
30- // Platform.OS = 'android';
31- // Instabug._isOnReportHandlerSet = jest.fn(() => true);
32- // const handler = global.ErrorUtils.getGlobalHandler();
33- // IBGEventEmitter.addListener(Instabug, IBGConstants.SEND_UNHANDLED_CRASH, (actual) => {
34- // const expected = {
35- // message: 'TypeError - This is a type error.',
36- // os: 'android',
37- // platform: 'react_native',
38- // exception: []
39- // };
40- // expect(actual).toEqual(expected);
41- // done();
42- // });
43- // handler({ name: 'TypeError', message: 'This is a type error.' }, false);
44- // });
32+ it ( 'should emit event IBGSendUnhandledJSCrash when platform is android and onReportSubmitHandler is set' , ( ) => {
33+ Platform . OS = 'android' ;
34+ InstabugUtils . setOnReportHandler ( true ) ;
35+ const handler = global . ErrorUtils . getGlobalHandler ( ) ;
36+ const callback = jest . fn ( ) ;
37+ IBGEventEmitter . addListener ( Instabug , IBGConstants . SEND_UNHANDLED_CRASH , callback ) ;
38+ handler ( { name : 'TypeError' , message : 'This is a type error.' } , false ) ;
39+
40+ expect ( callback ) . toHaveBeenCalledWith ( {
41+ message : 'TypeError - This is a type error.' ,
42+ e_message : 'This is a type error.' ,
43+ e_name : 'TypeError' ,
44+ os : 'android' ,
45+ platform : 'react_native' ,
46+ exception : [ ] ,
47+ } ) ;
48+ } ) ;
4549} ) ;
0 commit comments