【问题标题】:Jest React Native Expo.fx.js encountered an unexpected tokenJest React Native Expo.fx.js 遇到了一个意外的令牌
【发布时间】:2021-03-26 14:44:58
【问题描述】:

这是使用 create-react-native-app

构建的样板 Expo 应用程序

这是我的 package.jsonjest 部分:

  "jest": {
    "preset": "react-native",
    "testEnvironment": "node"
  },

这是我尝试运行 jest 时的输出:

> jest

 FAIL  src/__tests__/App.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /home/charney/om/star-harvester-centauri/node_modules/expo/build/Expo.fx.js:1
    import './environment/react-native-logs.fx';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime._execModule (node_modules/jest-runtime/build/index.js:1157:58)
      at Object.<anonymous> (node_modules/expo/src/Expo.ts:1:1)

【问题讨论】:

    标签: javascript react-native ecmascript-6 jestjs expo


    【解决方案1】:

    Jest encountered an unexpected token with react-native的答案相同

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-10
      • 2019-03-22
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      相关资源
      最近更新 更多