PhantomJS/Chrome 在 Angular 6 项目中使用 "Zone\nat"/"Script error" 在 Karma 测试中失败

PhantomJS/Chrome fails in Karma test with "Zone\nat"/"Script error" in an Angular 6 project

大家好 Whosebug,

我卡住了!我的 ng test 失败了,尽管 ng serve 可以毫无问题地构建和编译这个 Angular 6 项目。我收到的错误如下:

此外,紧接着 Chrome 失败,就像这样:

我几乎不了解发生了什么,但是这个问题阻止了成功部署,因为 build-street 失败了。

作为一个菜鸟,我正在疯狂地尝试应用与我的问题非常相似的解决方案,但无济于事。这就是为什么我向你们寻求帮助的原因!我试过 ;将 polyfills.ts 中的 import 'zone.js/dist/zone' 放在文件的顶部;更新 PhantomJS 等等。

我的karma.conf.js如下:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-phantomjs-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    /*...*/
    browsers: ['Chrome', 'PhantomJS'],
    singleRun: true
  });
};

不知道是否有帮助,但我的 package.json 看起来像这样:

 {
  "name": "isms-frontend",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "prepare": "patch-package"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.1.8",
    "@angular/cdk": "^6.4.7",
    "@angular/common": "6.1.8",
    "@angular/compiler": "6.1.8",
    "@angular/core": "6.1.8",
    "@angular/forms": "6.1.8",
    "@angular/http": "6.1.8",
    "@angular/material": "^6.4.7",
    "@angular/platform-browser": "6.1.8",
    "@angular/platform-browser-dynamic": "6.1.8",
    "@angular/router": "6.1.8",
    "core-js": "^2.5.4",
    "hammerjs": "^2.0.8",
    "intl": "^1.2.5",
    "ngx-window-core": "^1.0.84",
    "rxjs": "6.3.2",
    "rxjs-compat": "6.3.2",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.8.0",
    "@angular-devkit/build-ng-packagr": "~0.8.0",
    "@angular/cli": "~6.2.1",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.4",
    "ng-packagr": "^4.1.0",
    "phantomjs-prebuilt": "^2.1.16",
    "patch-package": "^5.1.1",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tsickle": ">=0.29.0",
    "tslib": "^1.9.0",
    "tslint": "~5.11.0",
    "typescript": "~2.9.2"
  }
}

如果有更多信息可以帮助解决此问题,请告诉我。提前感谢您的宝贵时间!

在经历了所有的痛苦之后,我发现我所要做的就是将参数传递给 ng test,就像我的 ng test isms-frontend 一样。从 jorgjanke 找到答案,最后从 https://github.com/angular/angular-cli/issues/12581

评论