react-native: ExceptionsManager.handleException is not a function
We recently upgraded to React Native 0.63, Jest 26, and React Native Testing Library 7. When running jest with --runInBand we have noticed the following error randomly in our CI:
/node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:104
ExceptionsManager.handleException(error, true);
^
TypeError: ExceptionsManager.handleException is not a function
at reportLogBoxError (/node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:108:21)
at Immediate.<anonymous> (/node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:217:7)
at processImmediate (internal/timers.js:456:21)
It appears that NativeExceptionsManager is mocked but handleException is not: https://github.com/facebook/react-native/blob/master/jest/setup.js#L42-L47
❯ npx envinfo --npmPackages react,react-native,react-test-renderer,@testing-library/react-native
npmPackages:
@testing-library/react-native: 7.0.2 => 7.0.2
react: 16.13.1 => 16.13.1
react-native: 0.63.2 => 0.63.2
react-test-renderer: 16.13.1 => 16.13.1
❯ react-native info
info Fetching system and libraries information...
System:
OS: macOS 10.15.6
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 746.34 MB / 32.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.3 - ~/.nvm/versions/node/v12.18.3/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.6 - ~/.nvm/versions/node/v12.18.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /Users/eliw00d/.rvm/gems/ruby-2.4.5/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK: Not Found
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6392135
Xcode: 11.6/11E708 - /usr/bin/xcodebuild
Languages:
Java: 11.0.4 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: Not Found
react-native: 0.63.2 => 0.63.2
npmGlobalPackages:
*react-native*: Not Found
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 13
- Comments: 15 (4 by maintainers)
Commits related to this issue
- Mocks to fix: handleException is not a function (#29849) — committed to lukewlms/react-native by lukewlms 4 years ago
Dropping a note here on what worked for us when we encountered this issue. We did a mock of
LogBoxin our jest setup file like that:For me, adding
jest.useFakeTimers()fix the problemWe’re seeing the same issue repeatedly, trying to test Apollo mutations with react-native-testing-library.
(This issue seems to totally swallow exception messages, so it is very painful when trying to debug unit tests!)
Environment info:
For now we can work around it just by moving this line to the top of
LogBoxData.js. Jest seems to be erroring out when it hits the inline require:const ExceptionsManager = require('../../Core/ExceptionsManager');…And adding this mock to jest/setup.js in RN:
Submitted PR: https://github.com/facebook/react-native/pull/30027
Is there an update on this issue? This is blocking my upgrade. It occurs when we are running our test suite.
what worked for me (@lukewlms’s solution works too but requires forking rn) was using
jest.useFakeTimers();for each failing test (I only had 2)Sure, I’ll submit what I have.
Thanks for the issue @eliw00d!
It looks like @lukewlms has a solution. Do you mind submitting a PR to fix the issue in core?