【问题标题】:Test suite failed to run , Jest encountered an unexpected token测试套件未能运行,Jest 遇到了意外的令牌
【发布时间】:2020-04-05 17:12:17
【问题描述】:

我在我的 Angular 应用程序中运行“npm run test”时遇到问题,控制台打印此消息“测试套件无法运行,Jest 遇到意外令牌”,我不知道为什么。

这是我在控制台中测试的结果:

Test Suites: 5 failed, 7 passed, 12 total
Tests:       24 passed, 24 total
Snapshots:   0 total
Time:        28.73s

这是我的设置:

babel.config.js:

 module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
    '@babel/preset-typescript',
  ],
};

package.json:

"jest": {
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "./setupJest.ts",
"testPathIgnorePatterns": [
  "./node_modules/",
  "./src/test.ts"
],

【问题讨论】:

    标签: angular testing jestjs


    【解决方案1】:

    将此添加到 tsconfig.spec.json 中的 compilerOptions:

    "module": "commonjs"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-10
      相关资源
      最近更新 更多