Reactotron: Error running tests on React Native

Created on 9 Jul 2017  ·  8Comments  ·  Source: infinitered/reactotron

Reproduce:

  • Create a simple project with react-native init (RN 0.46.1)
  • Set up Reactotron (exactly as described here)
  • Run _npm t_
  • Tests fail. Cause TypeError: Cannot read property 'updateExceptionMessage' of undefined

console:

FAIL __tests__/index.android.js
● Test suite failed to run

TypeError: Cannot read property 'updateExceptionMessage' of undefined

  at trackGlobalErrors (node_modules/reactotron-react-native/dist/index.js:72:61)
  at Client.Object.<anonymous>.trackGlobalErrors (node_modules/reactotron-react-native/dist/index.j

s:85:5)
at Client.use (node_modules/reactotron-core-client/dist/index.js:605:44)
at Client.Object..reactotron.useReactNative (node_modules/reactotron-react-native/dist
/index.js:715:16)
at Object. (ReactotronConfig.js:5:1)
at Object. (index.android.js:6:1)

FAIL __tests__/index.ios.js
● Test suite failed to run

TypeError: Cannot read property 'updateExceptionMessage' of undefined

  at trackGlobalErrors (node_modules/reactotron-react-native/dist/index.js:72:61)
  at Client.Object.<anonymous>.trackGlobalErrors (node_modules/reactotron-react-native/dist/index.j

s:85:5)
at Client.use (node_modules/reactotron-core-client/dist/index.js:605:44)
at Client.Object..reactotron.useReactNative (node_modules/reactotron-react-native/dist
/index.js:715:16)
at Object. (ReactotronConfig.js:5:1)
at Object. (index.ios.js:6:1)

Test Suites: 2 failed, 2 total
Tests: 0 total
Snapshots: 0 total
Time: 1.152s
Ran all test suites.

If I remove _import './ReactotronConfig'_ from index.android.js or index.ios.js files, test pass

Application and Reactotron work perfectly with react-native run

All 8 comments

Basically what is happening is the trackGlobalErrors is trying to hook into NativeModules.ExceptionsManager.updateExceptionMessage which likely isn't mocked in the default jest setup. This should be solved by mocking NativeModules.ExceptionsManager with even an empty object.

Even without using trackGlobalErrors on the ReactotronConfig.js file?

How would you mock NativeModules.ExceptionsManager? I cant find it with search all files

If you don't have trackGlobalErrors it shouldn't crash - can you provide your ReactotronConfig.js?

import Reactotron from 'reactotron-react-native'

Reactotron
  .configure() // controls connection & communication settings
  .useReactNative() // add all built-in react native plugins
  .connect() // let's connect!

.useReactNative() actually wires up trackGlobalErrors. Try this and see if it fixes this issue (for a short term fix until I work out the proper way to mock it):

.useReactNative({
    errors: false,
})

It did! Thanks!

@aschenkel PR created to fix this issue for real. I couldn't find a good way to fix this with a Jest mock since that would essentially be adding to a mock that exists which I guess isn't a thing...? Anyway... I added a check when wiring up trackGlobalErrors so that it can run in testing environments successfully while still being enabled for device environments. Once this lands you can drop the errors: false configuration if you feel so inclined.

Merged. Will release shortly. On a plane ATM.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dhruwal picture dhruwal  ·  3Comments

Anahkiasen picture Anahkiasen  ·  5Comments

fkereki picture fkereki  ·  3Comments

wilr picture wilr  ·  3Comments

davidjb picture davidjb  ·  5Comments