Facing issue with bugsnag mocking in react native
Error -
FAIL tests/App-test.js ● renders correctly
TypeError: _reactNative.default.start is not a function 40 | // StatusBar.setBackgroundColor(blueVersion.secondary); 41 | // StatusBar.setTranslucent(true); > 42 | Bugsnag.start(); | ^ 43 | UserExperior.startRecording(CONFIG_KEYS['USER_EXPERIOR_KEY']); 44 | deviceData(); 45 | SplashScreen.hide(); at src/App.js:42:13 at commitHookEffectListMount (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12999:26) at commitPassiveMountOnFiber (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14422:11) at commitPassiveMountEffects_complete (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14382:9) at commitPassiveMountEffects_begin (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14369:7) at commitPassiveMountEffects (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14357:3) at flushPassiveEffectsImpl (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:16248:3) at flushPassiveEffects (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:16197:14) at performSyncWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:15413:3) at flushSyncCallbacks (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2597:22)
Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 1.235s, estimated 2s
Solution Tried -
jest.mock('@bugsnag/react-native', () => ({
use(plugin) {
const boundary = plugin.init();
// we don't need the error boundary to swallow the errors, we want jest see them and fail the test
delete boundary.prototype.componentDidCatch;
return boundary;
},
}));
In jest setup js yet not working.
I also had a lot of problems with calls to Bugsnag
in the jest environment. Ultimately solved it by manually mocking it in __mocks__/@bugsnag/react-native.js
:
module.exports = {
addOnError: jest.fn(),
notify: jest.fn(),
// add other functions here if you need them
};