【问题标题】:How to avoid integration ios when testing React Native App?测试 React Native App 时如何避免集成 ios?
【发布时间】:2019-12-11 20:30:30
【问题描述】:

我对 react-native-firebase 有一些问题, 我有一个 Windows 环境,我想使用 Jest 进行测试, 因此,当我运行 npm test 时,我得到 Test suite failed

因为我有一个 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.

【问题讨论】:

  • 抄送:@auticcat !

标签: reactjs unit-testing react-native jestjs react-native-firebase


【解决方案1】:

您可以使用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();
});

}

【讨论】:

  • 我之前已经这样做了,但我得到了相同的结果“失败”!
猜你喜欢
  • 1970-01-01
  • 2020-01-06
  • 2017-09-16
  • 1970-01-01
  • 2022-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多