【问题标题】:Not sure how to handle the error "unexpected token"不确定如何处理错误“意外令牌”
【发布时间】:2019-10-06 10:35:59
【问题描述】:

我正在尝试将 jest 应用于 react-redux 代码,但现在我陷入了 env 设置。似乎错误与babel有关。尽管互联网上有很多关于“意外令牌”的信息,但我仍然无法解决问题。列出我的设置以供参考。

欢迎提出任何建议。

package.json 中的脚本(我使用“npm run test”开始测试),

  "scripts": {
    "test": "jest",
    "test:watch": "jest --watch",
    "test:clear": "jest --clearCache"
  },

babel 部分如下所示,

  "babel": {
    "env": {
      "test": {
        "presets": [
          "env"
        ],
        "only": [
          "./**/*.js",
          "node_modules/jest-runtime"
        ]
      }
    },
  }

devDependencies(babel相关的都在这里)

  "devDependencies": {
    "@babel/core": "^7.4.4",
    "@babel/preset-env": "^7.4.4",
    "@babel/runtime": "^7.4.4",
    "babel-core": "^6.26.3",
    "babel-jest": "^24.8.0",
    "babel-preset-env": "^1.7.0",
    "bili": "^4.8.0",
    "jest": "^24.8.0",
    "regenerator-runtime": "^0.13.2"
  },

开玩笑的部分,

  "jest": {
    "setupFilesAfterEnv": [
      "<rootDir>/__tests__/setup/setupEnzyme.js"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>/__tests__/setup/"
    ]
  },

【问题讨论】:

  • 你能从package.json文件中发布jest部分吗?
  • 您的package.json 是否在dependenciesdevDependencies 部分中包含@babel/runtime
  • 我愿意。我还在帖子中列出了与 babel 相关的依赖项。

标签: jestjs babeljs babel-jest


【解决方案1】:

我参考了https://www.freecodecamp.org/news/how-to-set-up-jest-enzyme-like-a-boss-8455a2bc6d56/ 来构建环境。错误可能与隐藏的配置文件有关。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 2011-12-20
    • 2015-11-19
    • 2018-08-27
    • 2014-12-07
    • 2016-08-10
    相关资源
    最近更新 更多