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 #532

Closed
eliw00d opened this issue Sep 2, 2020 · 5 comments
Closed

ExceptionsManager.handleException is not a function #532

eliw00d opened this issue Sep 2, 2020 · 5 comments

Comments

@eliw00d
Copy link

eliw00d commented Sep 2, 2020

Describe the bug

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)

I noticed a similar error in the previous project: testing-library/native-testing-library#132

Any thoughts?

Expected behavior

No errors.

Versions

❯ 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 
@thymikee
Copy link
Member

thymikee commented Sep 3, 2020

This library has nothing to do with LogBox, nor ExceptionsManager. Make sure to use "react-native" Jest preset and mock the native module if necessary. Looks like ExceptionsManager is already mocked, but handleException is not there: https://github.com/facebook/react-native/blob/master/jest/setup.js#L42

@thymikee thymikee closed this as completed Sep 3, 2020
@lukewlms
Copy link

lukewlms commented Sep 10, 2020

@thymikee Trying to deal with this too (discussing on RN GH) - can you help me understand why some parts of RN are mocked by RNTL but not others? E.g. LogBox is but not ExceptionManager. Is that b/c LogBox is a Component?

RNTL has this:

// Mock LogBox
jest.mock('react-native/Libraries/LogBox/LogBox');

But not something like this:

jest.mock("react-native/Libraries/Core/ExceptionsManager", () => ({
  handleException: (...args: any[]) => console.log(args),
}));

It also seems odd that despite LogBox being apparently mocked by RNTL, these errors still appear... perhaps because LogBox/LogBox is mocked but LogBox/Data is not. Not sure if the RNTL team would consider that in scope or not.

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)

FYI we can get around this issue ok by moving this line to the top of LogBoxData.js in node_modules/react-native:

const ExceptionsManager = require('../../Core/ExceptionsManager');

And adding this to the mocks in jest/setup.js:

  .mock("../Libraries/Core/ExceptionsManager", () => {
    return {
      handleException: (...args) => {
        return;
      },
    };
  })

@thymikee
Copy link
Member

RNTL provides no mocks on its own, where did you get that information from? It's "react-native" Jest preset that ships with React Native that handles mocking for Jest. If something is not there, while it should, send a PR to the core RN repo :)

@lukewlms
Copy link

Ah somehow I hallucinated that 🙂 thanks for the info!!

@gustavommarini
Copy link

gustavommarini commented Sep 1, 2021

I tried to avoid edit the LogBoxData.js and this solved my problem. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants