【问题标题】:Terminal error: Schema validation failed with the following errors: Data path "['polyfills']" should be array终端错误:架构验证失败,出现以下错误:数据路径“['polyfills']”应该是数组
【发布时间】:2025-12-22 04:05:13
【问题描述】:

我刚刚使用 ng new <projectName> 创建了一个新的 Angular 应用程序。然后我使用ng add @cypress/schematicng add @briebug/jest-schematic 更改了默认测试设置

package.lock供参考:

{
  "name": "betting-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "cypress:open": "cypress open",
    "cypress:run": "cypress run"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~11.1.2",
    "@angular/common": "~11.1.2",
    "@angular/compiler": "~11.1.2",
    "@angular/core": "~11.1.2",
    "@angular/forms": "~11.1.2",
    "@angular/platform-browser": "~11.1.2",
    "@angular/platform-browser-dynamic": "~11.1.2",
    "@angular/router": "~11.1.2",
    "@briebug/jest-schematic": "^3.1.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.11.3"
  },
  "devDependencies": {
    "@angular-builders/jest": "latest",
    "@angular-devkit/build-angular": "~0.1101.4",
    "@angular/cli": "~11.1.4",
    "@angular/compiler-cli": "~11.1.2",
    "@cypress/schematic": "^1.5.3",
    "@types/jasmine": "~3.6.0",
    "@types/jest": "latest",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "jest": "latest",
    "karma-coverage": "~2.0.3",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.1.2",
    "cypress": "latest"
  }
}

当我运行ng test 时,我收到了上述错误,并且正在为如何让我的测试运行而苦苦挣扎。任何帮助都会很棒!提前致谢。

【问题讨论】:

    标签: angular jestjs cypress


    【解决方案1】:

    我通过搜索 Google 找到了答案 here

    为什么在你的test 目标中需要polyfills 条目? 使用@angular-builders/jest 构建器? Here 是构建器的架构,它不包含 polyfills 字段。这 您收到此错误的原因是所有额外的 (非模式)字段被认为是an array of strings (这样您就可以像您一样将文件名传递给ng test 将它们传递给jest)。

    我的猜测是 polyfills 是 Karma builder 的剩余部分,您可以 安全地删除它。 angular.json 中唯一需要的选项是那些 提及 here.

    【讨论】:

    • 请总结你的研究并写下你自己的答案。
    最近更新 更多