react-native
react-native copied to clipboard
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
:warning: | Missing Environment Information |
---|---|
:information_source: | Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console. |
We'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!)
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
at parseErrorStack (node_modules/react-native/Libraries/Core/Devtools/parseErrorStack.js:53:26)
at Immediate._onImmediate (node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:192:48)
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
at reportLogBoxError (node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:85:27)
at Immediate._onImmediate (node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:202:7)
mobile2mr/node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:94
ExceptionsManager.handleException(error, true);
^
TypeError: ExceptionsManager.handleException is not a function
at handleException (mobile2mr/node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:108:21)
at Immediate.reportLogBoxError (mobile2mr/node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:217:7)
at processImmediate (internal/timers.js:456:21)
Environment info:
System:
OS: macOS 10.15.6
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 49.95 MB / 16.00 GB
Shell: 5.5.1 - /usr/local/bin/zsh
Binaries:
Node: 12.18.3 - /usr/local/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 6.14.6 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.7, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 23, 26, 27, 28, 29
Build Tools: 23.0.1, 26.0.1, 27.0.3, 28.0.3, 29.0.2
System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-28 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 3.1 AI-173.4720617
Xcode: 11.7/11E801a - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_171 - /usr/bin/javac
Python: 2.7.15 - /usr/local/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: ^0.63.2 => 0.63.2
npmGlobalPackages:
*react-native*: Not Found
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:
.mock("../Libraries/Core/ExceptionsManager", () => {
return {
handleException: (...args) => {
return;
},
};
})
Thanks for the issue @eliw00d!
It looks like @lukewlms has a solution. Do you mind submitting a PR to fix the issue in core?
Sure, I'll submit what I have.
Is there an update on this issue? This is blocking my upgrade. It occurs when we are running our test suite.
Submitted PR: https://github.com/facebook/react-native/pull/30027
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)
Appreciate submitting the PR!
Commented on the PR - I'd like to take a look at this, could someone set up a minimal reproduction for me?
For me, adding jest.useFakeTimers()
fix the problem
beforeEach(() => {
jest.resetModules();
jest.resetAllMocks();
jest.useFakeTimers(); // <-- Add this
});
Dropping a note here on what worked for us when we encountered this issue. We did a mock of LogBox
in our jest setup file like that:
jest.mock('react-native/Libraries/LogBox/LogBox')
great @lingumi-remy it works!
i have sama the problem
`/Users/
TypeError: ExceptionsManager.handleException is not a function
at reportLogBoxError (/Users/
maybe you forget add sync on test, i am bad for test
example wrong test `describe('International Order snapshot test', () => { it('should render correctly', () => { const store = createStore(storeModel);
const tree = render(
<StoreProvider store={store}>
<InternationalOrder route={mockRoute as never} navigation={mockNavigation as never} />
</StoreProvider>,
options,
).toJSON();
expect(tree).toMatchSnapshot();
});
});`
and example true, like this : `describe('International Order snapshot test', () => { it('should render correctly', async () => { --> async const store = createStore(storeModel);
const tree = render(
<StoreProvider store={store}>
<InternationalOrder route={mockRoute as never} navigation={mockNavigation as never} />
</StoreProvider>,
options,
).toJSON();
await waitForRender(200); --> waiting render 200 ms
expect(tree).toMatchSnapshot();
});
});`
this fix my issues
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.