react-native-qrcode-scanner icon indicating copy to clipboard operation
react-native-qrcode-scanner copied to clipboard

Test fails due to react-native-permissions

Open rajAmukhliS opened this issue 3 years ago • 2 comments

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

rajAmukhliS avatar Feb 09 '22 05:02 rajAmukhliS

I have found 2 ways to get rid of this 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());

  1. mock react-native-qrcode-scanner inside the jest.setup.js file , this is solution for all tests files as shown below write 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'),
);

rajAmukhliS avatar Feb 09 '22 05:02 rajAmukhliS

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 🙏

moaazsidat avatar Feb 11 '22 23:02 moaazsidat