javascript - 指定的插件 0,提供了 "default"的无效属性(Jest React Native)

标签 javascript react-native jestjs

嘿,我只是想运行一个简单的测试,在运行使用 jest 的“ yarn 测试”后,我一直遇到这个错误。

Plugin 0 specified in "/Users/Documents/Dev/appname/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default" (While processing preset: "/Users/Documents/Dev/appname/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)

这是我的 package.json,我缺少什么,我确定它是配置问题而不是测试问题。

{
  "name": "appname",
  "version": "0.0.1",
  "private": true,
  "rnpm": {
    "assets": [
      "resources/fonts"
    ]
  },
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "lodash": "^4.17.10",
    "react": "16.4.1",
    "react-native": "0.56.0",
    "react-native-autocomplete-input": "^3.5.0",
    "react-native-code-push": "^5.4.2",
    "react-native-elements": "^1.0.0-beta2",
    "react-native-form-validator": "^0.2.0",
    "react-native-image-pan-zoom": "^2.1.9",
    "react-native-image-zoom-viewer": "^2.2.18",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-remote-svg": "^1.3.0",
    "react-native-vector-icons": "^5.0.0",
    "react-native-version-number": "^0.3.5",
    "react-navigation": "^2.11.2"
  },
  "devDependencies": {
    "babel-jest": "23.4.2",
    "babel-preset-react-native": "^5",
    "jest": "23.5.0",
    "react-test-renderer": "16.4.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

最佳答案

不知道你是否已经解决了这个问题,但我遇到了同样的问题,我能够使用 RN 0.56 使事情再次正常工作。我改变了这个:

"babel-preset-react-native": "^5",

"babel-preset-react-native": "4.0.0",

这里是关于这个问题的完整讨论:https://github.com/storybooks/storybook/issues/3897

如果以上破坏了你的 react-native 环境,另一种解决方案是安装 babel-bridge:

npm install babel-core@7.0.0-bridge.0 --save-dev

关于javascript - 指定的插件 0,提供了 "default"的无效属性(Jest React Native),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53378066/

相关文章:

react-native - 使用 react-navigation 中的 useRoute 进行 Jest 单元测试

javascript - 当 HTML 元素的内容完全加载时是否有一个事件?

javascript - 如何在点击事件中切换两个词

java - 从 Android 中的 Native Java Activity 打开 React Native 组件

react-native - 使用 expo sdk43 运行鳍状肢

typescript - 如何使用 Jest 和 TypeScript 模拟第三方 nodejs 模块功能?

javascript - OnKeyUp 事件的十进制检查

javascript - 带有 onLeave 和 afterLoad 的 fullpage.js 动画

android - 在 Android 上 React Native,使用获取的 ajax 调用失败

javascript - 在 NodeJs 中使用 Jest 模拟 Http Post 请求