首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于反应本机权限,测试失败。

由于反应本机权限,测试失败。
EN

Stack Overflow用户
提问于 2022-02-09 06:04:43
回答 1查看 531关注 0票数 0

测试由于反应本机权限而失败

输出:

代码语言:javascript
复制
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-scannerreact-native-permissions之前,所有测试都是正常的,工作正常。

这是我的输出附加了我所面临的错误

我还在项目的根dir中的jest.setup.js文件中模拟了react-native-permissions,如下所示,它仍然不起作用。

代码语言:javascript
复制
jest.mock('react-native-permissions', () =>
  require('react-native-permissions/mock'),
);

在安装时,我忽略了这个pakage所需的ios信任,因为我只在为android开发ubuntu,只有

感谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2022-02-09 06:08:24

我找到了两种解决问题的方法

1.测试文件中的模拟react-native-qrcode-scanner,这是单个文件的解决方案,如下所示,导入后在测试文件的顶部写入react-native-qrcode-scanner的模拟

代码语言:javascript
复制
jest.mock('react-native-qrcode-scanner', () => jest.fn());

  1. 模拟react-native-qrcode-scanner在项目的根dir中的jest.setup.js文件中,这是所有测试文件的解决方案,如下所示:

在根dir中的jest.setup.js文件中写入react-native-qrcode-scanner的模拟,如下所示

代码语言:javascript
复制
jest.mock(
  'react-native-qrcode-scanner/node_modules/react-native-permissions',
  () => require('react-native-permissions/mock'),
);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71044706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档