Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExceptionsManager.handleException is not a function #29849

Closed
eliw00d opened this issue Sep 3, 2020 · 15 comments
Closed

ExceptionsManager.handleException is not a function #29849

eliw00d opened this issue Sep 3, 2020 · 15 comments
Labels
LogBox Resolution: PR Submitted A pull request with a fix has been provided. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@eliw00d
Copy link

eliw00d commented Sep 3, 2020

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
@react-native-bot react-native-bot added Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. and removed Needs: Triage 🔍 labels Sep 3, 2020
@github-actions
Copy link

github-actions bot commented Sep 3, 2020

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Sep 3, 2020
@lukewlms
Copy link

lukewlms commented Sep 10, 2020

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;
      },
    };
  })

@safaiyeh safaiyeh added LogBox and removed Needs: Attention Issues where the author has responded to feedback. Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. labels Sep 11, 2020
@safaiyeh
Copy link
Contributor

Thanks for the issue @eliw00d!

It looks like @lukewlms has a solution. Do you mind submitting a PR to fix the issue in core?

@lukewlms
Copy link

Sure, I'll submit what I have.

@owencraston
Copy link

Is there an update on this issue? This is blocking my upgrade. It occurs when we are running our test suite.

@lukewlms
Copy link

Submitted PR: #30027

@KrumTy
Copy link

KrumTy commented Oct 23, 2020

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)

@safaiyeh safaiyeh added the Resolution: PR Submitted A pull request with a fix has been provided. label Oct 23, 2020
@safaiyeh
Copy link
Contributor

safaiyeh commented Oct 23, 2020

Appreciate submitting the PR!

@rickhanlonii
Copy link
Member

Commented on the PR - I'd like to take a look at this, could someone set up a minimal reproduction for me?

@rnike
Copy link
Contributor

rnike commented Nov 27, 2020

For me, adding jest.useFakeTimers() fix the problem

  beforeEach(() => {
    jest.resetModules();
    jest.resetAllMocks();
    jest.useFakeTimers();  // <-- Add this
  });

@lingumi-remy
Copy link

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')

@GoMino
Copy link

GoMino commented Oct 21, 2021

great @lingumi-remy it works!

@fandu139
Copy link

fandu139 commented Apr 6, 2022

i have sama the problem
`/Users///node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:108
ExceptionsManager.handleException(error, true);
^

TypeError: ExceptionsManager.handleException is not a function
at reportLogBoxError (/Users///node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:108:21)
at Immediate. (/Users///node_modules/react-native/Libraries/LogBox/Data/LogBoxData.js:205:7)`

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

@github-actions
Copy link

github-actions bot commented Jul 9, 2023

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.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 9, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LogBox Resolution: PR Submitted A pull request with a fix has been provided. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests