测试由于反应本机权限而失败
输出:
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)平台:操作系统和安卓系统
在安装react-native-qrcode-scanner和react-native-permissions之前,所有测试都是正常的,工作正常。
这是我的输出附加了我所面临的错误
我还在项目的根dir中的jest.setup.js文件中模拟了react-native-permissions,如下所示,它仍然不起作用。
jest.mock('react-native-permissions', () =>
require('react-native-permissions/mock'),
);在安装时,我忽略了这个pakage所需的ios信任,因为我只在为android开发ubuntu,只有。
感谢你的帮助
发布于 2022-02-09 06:08:24
我找到了两种解决问题的方法
1.测试文件中的模拟react-native-qrcode-scanner,这是单个文件的解决方案,如下所示,导入后在测试文件的顶部写入react-native-qrcode-scanner的模拟
jest.mock('react-native-qrcode-scanner', () => jest.fn());react-native-qrcode-scanner在项目的根dir中的jest.setup.js文件中,这是所有测试文件的解决方案,如下所示:在根dir中的jest.setup.js文件中写入react-native-qrcode-scanner的模拟,如下所示
jest.mock(
'react-native-qrcode-scanner/node_modules/react-native-permissions',
() => require('react-native-permissions/mock'),
);https://stackoverflow.com/questions/71044706
复制相似问题