Amal
Amal

Reputation: 545

React native customBubblingEventTypes error when running tests

I am running a simple test to render react native component using enzyme and jest. It's a monorepo setup using lerna for web and mobile with shared components. There is babel, jest config that's shared between packages. The app starts and works successfully using the component that I am testing without any warnings or errors. But for some weird reason when I run a test, I am getting this error

● Test suite failed to run TypeError: Cannot read property 'customBubblingEventTypes' of undefined at node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2357:8 at Object. (node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:17:3) at Object. (node_modules/react-native/Libraries/Renderer/shims/ReactNative.js:18:17)

This is the info from react-native info command.

info Fetching system and libraries information...
System:
    OS: macOS 10.15.3
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 377.90 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.16.0 - ~/.nvm/versions/node/v12.16.0/bin/node
    Yarn: Not Found
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.0/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.9.1 - /Users/amal/.rvm/gems/ruby-2.3.1/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 27, 28
      Build Tools: 27.0.3, 28.0.3
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_202 - /usr/bin/javac
    Python: 2.7.17 - /usr/local/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: 0.63.0 => 0.63.0 
  npmGlobalPackages:
    *react-native*: Not Found

react and @react-native-community/cli is installed in root node-modules as hoisted by lerna in monorepo. maybe that's why the cli says it's not found.

This is a new react native setup with only the babel and shared node_modules as customised changes code. Only the test fails and it would be great if somebody can give insights. Thanks in advance.

Upvotes: 0

Views: 235

Answers (1)

Amal
Amal

Reputation: 545

This error was related to enzyme and not react native. It looks like though the enzyme website says it can be made to work with react-native, when using other packages like styled-components it never works. https://github.com/enzymejs/enzyme/issues/1436 - In case anyone is interested to follow the conversation in enzyme repo. I used https://github.com/callstack/react-native-testing-library instead of enzyme for testing react native and it works smoothly!

Upvotes: 0

Related Questions