react-native-qrcode-scanner
react-native-qrcode-scanner copied to clipboard
Test fails due to react-native-permissions
Discussed in https://github.com/moaazsidat/react-native-qrcode-scanner/discussions/371
Originally posted by rajAmukhliS February 9, 2022
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 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
I have found 2 ways to get rid of this issue
- mock
react-native-qrcode-scanner
inside the test file , this is solution for single file as shown below write mock ofreact-native-qrcode-scanner
on top of test file after imports
jest.mock('react-native-qrcode-scanner', () => jest.fn());
- mock
react-native-qrcode-scanner
inside the jest.setup.js file , this is solution for all tests files as shown below write mock ofreact-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'),
);
Do you think one of them is better than the other? If so, please consider documenting and submitting a pull request to improve the readme, thanks 🙏