angulargoogle-chromephantomjskarma-jasminezone

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


Hi people of the StackOverflow,

I am stuck! My ng test fails, although ng serve builds and compiles this Angular 6 project with no issues. The error I am getting is the following:

Karma fails

Additionally, immediately after that Chrome fails, just as so:

enter image description here

I have little to no understanding of what's happening, but this issue prevents the successful deploy, as the build-street fails.

As a big noob I am furiously going in a loop of trying to apply solutions that closely resembles my issue, but with no avail. That is why I am asking you guys for help! I've tried doing PhantomJS does not work with Karma in Angular2 project; put import 'zone.js/dist/zone' from polyfills.ts in the top of the file; updating PhantomJS and what not.

My karma.conf.js is as follows:

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
  });
};

Don't know if it'll help but my package.json looks like this:

 {
  "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"
  }
}

Please let me know if any more information can help resolve this issue. Thanks in advance for your time!


Solution

  • After all the suffering I found out that all I had to do is pass an argument to ng test, just as ng test isms-frontend in my case. Found the answer from jorgjanke last comment from https://github.com/angular/angular-cli/issues/12581