|
1 | 1 | import '../mocks/mockInstabugUtils'; |
2 | 2 |
|
3 | | -import { NativeModules, Platform, findNodeHandle, processColor } from 'react-native'; |
| 3 | +import { Platform, findNodeHandle, processColor } from 'react-native'; |
4 | 4 |
|
5 | 5 | import waitForExpect from 'wait-for-expect'; |
6 | 6 |
|
7 | 7 | import Report from '../../src/models/Report'; |
8 | 8 | import * as Instabug from '../../src/modules/Instabug'; |
9 | | -import { NativeCrashReporting, NativeInstabug } from '../../src/native'; |
| 9 | +import { NativeInstabug } from '../../src/native'; |
10 | 10 | import { |
11 | 11 | ColorTheme, |
12 | 12 | InvocationEvent, |
@@ -610,16 +610,6 @@ describe('Instabug Module', () => { |
610 | 610 | expect(NativeInstabug.show).toBeCalledTimes(1); |
611 | 611 | }); |
612 | 612 |
|
613 | | - it('should set _isOnReportHandlerSet to true on calling onReportSubmitHandler', () => { |
614 | | - Instabug.onReportSubmitHandler(jest.fn()); |
615 | | - expect(InstabugUtils.setOnReportHandler).toBeCalledWith(true); |
616 | | - }); |
617 | | - |
618 | | - it('should set _isOnReportHandlerSet to false on calling onReportSubmitHandler without a handler', () => { |
619 | | - Instabug.onReportSubmitHandler(); |
620 | | - expect(InstabugUtils.setOnReportHandler).toBeCalledWith(false); |
621 | | - }); |
622 | | - |
623 | 613 | it('should call the native method setPreSendingHandler with a function', () => { |
624 | 614 | const callback = jest.fn(); |
625 | 615 | Instabug.onReportSubmitHandler(callback); |
@@ -651,97 +641,6 @@ describe('Instabug Module', () => { |
651 | 641 | expect(IBGEventEmitter.getListeners(IBGConstants.PRESENDING_HANDLER).length).toEqual(1); |
652 | 642 | }); |
653 | 643 |
|
654 | | - it('should invoke callback on emitting the event IBGSendHandledJSCrash', async (done) => { |
655 | | - Platform.OS = 'android'; |
656 | | - const report = { |
657 | | - tags: ['tag1', 'tag2'], |
658 | | - consoleLogs: ['consoleLog'], |
659 | | - instabugLogs: ['instabugLog'], |
660 | | - userAttributes: [{ age: '24' }], |
661 | | - fileAttachments: ['path'], |
662 | | - }; |
663 | | - NativeModules.Instabug.getReport.mockResolvedValue(report); |
664 | | - const jsonObject = { stack: 'error' }; |
665 | | - const callback = (rep: Report) => { |
666 | | - expect(rep).toBeInstanceOf(Report); |
667 | | - expect(rep.tags).toBe(report.tags); |
668 | | - expect(rep.consoleLogs).toBe(report.consoleLogs); |
669 | | - expect(rep.instabugLogs).toBe(report.instabugLogs); |
670 | | - expect(rep.userAttributes).toBe(report.userAttributes); |
671 | | - expect(rep.fileAttachments).toBe(report.fileAttachments); |
672 | | - done(); |
673 | | - }; |
674 | | - Instabug.onReportSubmitHandler(callback); |
675 | | - IBGEventEmitter.emit(IBGConstants.SEND_HANDLED_CRASH, jsonObject); |
676 | | - |
677 | | - expect(IBGEventEmitter.getListeners(IBGConstants.SEND_HANDLED_CRASH).length).toEqual(1); |
678 | | - await waitForExpect(() => expect(NativeCrashReporting.sendHandledJSCrash).toBeCalledTimes(1)); |
679 | | - await waitForExpect(() => |
680 | | - expect(NativeCrashReporting.sendHandledJSCrash).toBeCalledWith(jsonObject), |
681 | | - ); |
682 | | - }); |
683 | | - |
684 | | - it('should not break if pre-sending callback fails on emitting the event IBGSendHandledJSCrash', async () => { |
685 | | - const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); |
686 | | - |
687 | | - Platform.OS = 'android'; |
688 | | - NativeModules.Instabug.getReport.mockResolvedValue({}); |
689 | | - const callback = jest.fn(() => { |
690 | | - throw new Error('Pre-sending callback failed.'); |
691 | | - }); |
692 | | - |
693 | | - Instabug.onReportSubmitHandler(callback); |
694 | | - IBGEventEmitter.emit(IBGConstants.SEND_HANDLED_CRASH, {}); |
695 | | - |
696 | | - // We don't care if console.error is called but we use it as a sign that the function finished running |
697 | | - await waitForExpect(() => expect(callback).toBeCalled()); |
698 | | - expect(NativeCrashReporting.sendHandledJSCrash).not.toBeCalled(); |
699 | | - |
700 | | - consoleSpy.mockRestore(); |
701 | | - }); |
702 | | - |
703 | | - it('should not invoke callback on emitting the event IBGSendHandledJSCrash when Platform is iOS', () => { |
704 | | - Platform.OS = 'ios'; |
705 | | - Instabug.onReportSubmitHandler(jest.fn()); |
706 | | - IBGEventEmitter.emit(IBGConstants.SEND_HANDLED_CRASH, {}); |
707 | | - expect(IBGEventEmitter.getListeners(IBGConstants.SEND_HANDLED_CRASH).length).toEqual(0); |
708 | | - }); |
709 | | - |
710 | | - it('should invoke callback on emitting the event IBGSendUnhandledJSCrash', async (done) => { |
711 | | - Platform.OS = 'android'; |
712 | | - const report = { |
713 | | - tags: ['tag1', 'tag2'], |
714 | | - consoleLogs: ['consoleLog'], |
715 | | - instabugLogs: ['instabugLog'], |
716 | | - userAttributes: [{ age: '24' }], |
717 | | - fileAttachments: ['path'], |
718 | | - }; |
719 | | - NativeModules.Instabug.getReport.mockResolvedValue(report); |
720 | | - const jsonObject = { stack: 'error' }; |
721 | | - const callback = (rep: Report) => { |
722 | | - expect(rep).toBeInstanceOf(Report); |
723 | | - expect(rep.tags).toBe(report.tags); |
724 | | - expect(rep.consoleLogs).toBe(report.consoleLogs); |
725 | | - expect(rep.instabugLogs).toBe(report.instabugLogs); |
726 | | - expect(rep.userAttributes).toBe(report.userAttributes); |
727 | | - expect(rep.fileAttachments).toBe(report.fileAttachments); |
728 | | - done(); |
729 | | - }; |
730 | | - Instabug.onReportSubmitHandler(callback); |
731 | | - IBGEventEmitter.emit(IBGConstants.SEND_UNHANDLED_CRASH, jsonObject); |
732 | | - |
733 | | - expect(IBGEventEmitter.getListeners(IBGConstants.SEND_UNHANDLED_CRASH).length).toEqual(1); |
734 | | - await waitForExpect(() => expect(NativeCrashReporting.sendJSCrash).toBeCalledTimes(1)); |
735 | | - await waitForExpect(() => expect(NativeCrashReporting.sendJSCrash).toBeCalledWith(jsonObject)); |
736 | | - }); |
737 | | - |
738 | | - it('should not invoke callback on emitting the event IBGSendUnhandledJSCrash when Platform is iOS', () => { |
739 | | - Platform.OS = 'ios'; |
740 | | - Instabug.onReportSubmitHandler(jest.fn()); |
741 | | - IBGEventEmitter.emit(IBGConstants.SEND_UNHANDLED_CRASH, {}); |
742 | | - expect(IBGEventEmitter.getListeners(IBGConstants.SEND_UNHANDLED_CRASH).length).toEqual(0); |
743 | | - }); |
744 | | - |
745 | 644 | it('should invoke the native method callPrivateApi', () => { |
746 | 645 | const apiName = 'name'; |
747 | 646 | const param = 'param'; |
|
0 commit comments