React-native-branch-deep-linking-attribution: Jest - Cannot read property 'setDebug' of undefined

Created on 14 Apr 2017  路  2Comments  路  Source: BranchMetrics/react-native-branch-deep-linking-attribution

Hey,

I have this error when running tests with jest

capture d ecran 2017-04-14 a 17 29 57

Do we have to mock something to make it works with jest?

Thanks,

Most helpful comment

Thanks for your reply @jdee. Sorry I didn't see #119.

I fixed it by adding RNBranch: {} in /node_module/react-native/jest/setup.js in the mockNativeModules object.
Sounds weird to have to add something in react-native but seems to work for now.

EDIT: Found another way which seems better than modifying react-native
Added theses lines in my jest configuration file:

// .jestsetup.js
import React from 'react-native'
React.NativeModules.RNBranch = {};

All 2 comments

Hi @iDams. I think this is the same as #119. I asked for more detail there, never got it, and closed the issue. But now I guess I can see roughly what's going on. The NPM module itself uses ava. It mocks the native RNBranch module. You can run npm test in this repo and see the one test case succeed. See test/helpers/RNBranch.mock.js. The RNBranchEventEmitter module was introduced in the master branch and hasn't been released yet, so you don't need that unless you're using master or 2.0.0-beta.1. The RNBranchEventEmitter will be released with 2.0.0-beta.2 soon, and then users of 2.0.0 will need it.

If there's a generic way of adding these mocks to the NPM module so that users don't have to add them, I'd like to do that and make this easier for everyone. For now, if you introduce your own mock, that will probably fix this issue for you.

Thanks for your reply @jdee. Sorry I didn't see #119.

I fixed it by adding RNBranch: {} in /node_module/react-native/jest/setup.js in the mockNativeModules object.
Sounds weird to have to add something in react-native but seems to work for now.

EDIT: Found another way which seems better than modifying react-native
Added theses lines in my jest configuration file:

// .jestsetup.js
import React from 'react-native'
React.NativeModules.RNBranch = {};
Was this page helpful?
0 / 5 - 0 ratings