Reputation: 1669
Test fails due to react-native-permissions
Output:
react-native-permissions: NativeModule.RNPermissions is null. To fix this issue try these steps:
• If you are using CocoaPods on iOS, run pod install in the ios directory and then clean, rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
• If you are getting this error while unit testing you need to mock the native module. You can use this to get started: https://github.com/react-native-community/react-native-permissions/blob/master/mock.js
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-permissions
at Object.<anonymous> (node_modules/react-native-qrcode-scanner/node_modules/react-native-permissions/lib/commonjs/index.ts:6:9)
at Object.<anonymous> (node_modules/react-native-qrcode-scanner/index.js:19:1)
Plateform: both ios and android
before installation of react-native-qrcode-scanner
and react-native-permissions
all tests were ok and working perfect
here is my output attached the error I am facing
I have also mocked react-native-permissions
in jest.setup.js file in root dir of project as shown below , still its not working
jest.mock('react-native-permissions', () =>
require('react-native-permissions/mock'),
);
at time of installation i ignored ios configrations required for this pakage because i am working on ubuntu for android only
shall be thankfull for your help
Upvotes: 0
Views: 1619
Reputation: 1669
I have found 2 ways to get rid of issue
1.mock react-native-qrcode-scanner
inside the test file , this is solution for single file as shown below
write mock of react-native-qrcode-scanner
on top of test file after imports
jest.mock('react-native-qrcode-scanner', () => jest.fn());
react-native-qrcode-scanner
inside the jest.setup.js file in root dir of project, this is solution for all tests files as shown belowwrite mock of react-native-qrcode-scanner
inside jest.setup.js file in root dir as shown below
jest.mock(
'react-native-qrcode-scanner/node_modules/react-native-permissions',
() => require('react-native-permissions/mock'),
);
Upvotes: 0