Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

Unable to mock appcenter module in React Native

$
0
0

Trying to use the AppCenter package within a React Native application and set the user id for crash reporting, however when my tests run I am getting the following error

console.warn src/common/services/loginService.ts:1584    Failed to log in TypeError: Cannot read property 'setUserId' of undefined        at Object.setUserId (C:\Users\David\Documents\DodsonCloudMobile\node_modules\appcenter\AppCenter.js:75:37)        at Object.<anonymous>.exports.setUserId (C:\Users\David\Documents\DodsonCloudMobile\src\common\services\appcenterWrapper.ts:117:22)        at LoginService.logIn (C:\Users\David\Documents\DodsonCloudMobile\src\common\services\loginService.ts:1546:32)        at processTicksAndRejections (internal/process/task_queues.js:85:5)        at Object.<anonymous> (C:\Users\David\Documents\DodsonCloudMobile\src\common\services\loginService.test.ts:113:7)

attempting to mock the appcenter module does not work. Looking at the source code for the AppCenter package the imports and function that are being referenced as followed

const ReactNative = require('react-native');const { AppCenterReactNative } = ReactNative.NativeModules;setUserId(userId) {        return AppCenterReactNative.setUserId(userId);    },

Upon seeing this I have attempted to then mock AppCenterReactNative and return setUserId as a jest.fn() but that led to the same error as well.


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>