reactjs - 测试 React Native App 时如何避免集成 ios?
问题描述
我对 react-native-firebase 有一些问题,我有一个Windows 环境,我想使用 Jest 进行测试,所以当我运行npm test
测试套件失败时
因为我有一个 react-native-firebase 包,它应该集成在 IOS 中,我只是重命名文件Android 并取消链接 react-native-firebase 以避免这些,但它对我不起作用!那么,如果我没有 Mac,我该如何处理
测试代码
/**
* @format
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/
import "react-native";
import React from "react";
import App from "../App";
import SignIn from "../src/screens/SignIn";
// Note: test renderer must be required after react-native.
import renderer from "react-test-renderer";
// it("renders correctly", () => {
// renderer.create(<App />);
// });
test("renders correctly", () => {
const tree = renderer.create(<SignIn />).toJSON();
expect(tree).toMatchSnapshot();
});
测试结果
FAIL __tests__/App.js
● Test suite failed to run
RNFirebase core module was not found natively on iOS, ensure you have correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.
See http://invertase.link/ios for the ios setup guide.
at new Firebase (node_modules/react-native-firebase/dist/modules/core/firebase.js:28:13)
at Object.<anonymous> (node_modules/react-native-firebase/dist/modules/core/firebase.js:97:21)
at Object.<anonymous> (node_modules/react-native-firebase/dist/index.js:1:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 6.137s
Ran all test suites.
npm ERR! Test failed. See above for more details.
解决方案
您可以使用import {Platform} from 'react-native';
import {Platform} from 'react-native';
if(Platform.OS !== 'ios') {
test("renders correctly", () => {
const tree = renderer.create(<SignIn />).toJSON();
expect(tree).toMatchSnapshot();
});
}
推荐阅读
- java - 将 Vaadin CheckBox 保存到 JPA 的正确方法是什么?
- reactjs - Reactjs - jquery 未在 npm 安装库中定义 - jquery.reel
- excel - 将用户窗体文本框中的文本粘贴到另一个工作表上的 ActiveCell 的相应单元格
- python - 在 Python 中使用 tkinter 打包帧的问题
- arrays - 如何用数组中的元素替换文件中的单词
- kubernetes - 转义 helm yml 进行部署
- django - 如何根据外键的主键上传文件?
- android - 如何在 AR 中将 3D 模型放置在屏幕中心,并相对于轴上的摄像机角度将其移动近或远?
- c# - LINQ如何在where子句中将方法变量作为列名传递
- java - 在初始化期间在 H2 数据库中设置别名