React Native-开玩笑:自更新至0.56以来已损坏.如何解决? [英] React Native - Jest: Broken since update to 0.56. How to fix it?

查看:216
本文介绍了React Native-开玩笑:自更新至0.56以来已损坏.如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从升级到新的React Native版本以来,我的测试就被破坏了.

Ever since upgrading to the new React Native version my tests are broken.

这是我的环境:

React Native Environment Info:
System:
  OS: macOS High Sierra 10.13.4
  CPU: x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  Memory: 486.81 MB / 16.00 GB

  Shell: 3.2.57 - /bin/bash
Binaries:
  Node: 9.4.0 - /usr/local/bin/node
  npm: 6.1.0 - /usr/local/bin/npm
  Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
  iOS SDK:
    Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
IDEs:
  Android Studio: 3.1 AI-173.4697961
  Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
  react: 16.4.1 => 16.4.1
  react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
  create-react-native-app: 1.0.0
  react-native-cli: 2.0.1
  react-native-git-upgrade: 0.2.7

说明

在尝试测试我新创建的动作创建者时,npm test抛出以下错误:

Description

While trying to test my newly created action creators,npm test throws the following error:

jest

 FAIL  app/actions/logout/logout.test.js
  ● Test suite failed to run


    Plugin 0 specified in "/Users/jan/Startup/react-native/ordersome/node_modules/babel-preset-react-native/index.js" provided an invalid
property of "default" (While processing preset: "/Users/jan/Startup/react-native/ordersome/node_modules/babel-preset-react-native/index.js
")

      at Plugin.init (node_modules/babel-core/lib/transformation/plugin.js:131:13)
      at Function.normalisePlugin (node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
          at Array.map (<anonymous>)
      at Function.normalisePlugins (node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
          at Array.map (<anonymous>)
      at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)

我在Google上搜索量很大,无法找到解决方法.似乎与通天塔有关.

I have googled heavily and can't find a fix. It seems like it has something to do with babel.

很容易复制(当前).我尝试使用react-native init启动了一个新项目.然后,我只是创建了一个随机的.test.js文件,并在其中编写了文档的入门测试:

It's easy to reproduce (currently). I tried an started a new project using react-native init. Then I just created a random .test.js file and wrote the getting started test of the documentation in it:

function sum(a, b) {
  return a + b;
}

test("adds 1 + 2 to equal 3", () => {
  expect(sum(1, 2)).toBe(3);
});

接下来,我运行'npm test',它给出了上面的错误.

Next I run 'npm test' and it gives the error above.

推荐答案

这是我修复它的方式.

添加

"@babel/core": "^7.0.0-beta.47",
"babel-core": "^7.0.0-beta.47",

package.json并运行npm install.这对我来说是固定的.

to your package.json and run npm install. This fixed it for me.

此外,您必须添加酶

   "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
    }

为您在package.json中的配置提供了帮助.

to you jest config in your package.json.

如果您希望获得更彻底的修复,请查看此github问题.

If you want to see a more thorough fix, check out this github issue.

这篇关于React Native-开玩笑:自更新至0.56以来已损坏.如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆