简体   繁体   中英

After completion of ng test, getting Uncaught [object Object] at /_karma_webpack_/polyfills.js

Test cases are running successfully but at the end it gets returned with an Uncaught [object Object] error which looks like this: -

在此处输入图像描述

Test script: ng test --codeCoverage=true --no-watch --no-progress --browsers=ChromeHeadless

Angular: 8

package.json dependencies: -

"dependencies": {
    "angular2-uuid": "^1.1.1",
    "body-parser": "1.19.0",
    "brotli": "1.3.2",
    "compression": "1.7.4",
    "convict": "6.2.3",
    "cors": "2.8.5",
    "dotenv": "6.2.0",
    "express": "4.17.1",
    "express-static-gzip": "1.1.3",
    "flatted": "2.0.2",
    "font-awesome": "4.7.0",
    "fs-extra": "8.1.0",
    "lodash": "4.17.21",
    "ngx-spinner": "^8.1.0",
    "nocache": "2.1.0",
    "npm": "8.19.1",
    "path": "0.12.7",
    "popper.js": "1.14.7",
    "postcss-syntax": "0.10.0",
    "request": "2.88.0",
    "url-search-params-polyfill": "7.0.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.800.6",
    "@angular/animations": "^8.2.9",
    "@angular/cdk": "^8.2.3",
    "@angular/cli": "^8.3.20",
    "@angular/common": "^8.2.9",
    "@angular/compiler": "^8.2.9",
    "@angular/compiler-cli": "^8.2.9",
    "@angular/core": "^8.2.9",
    "@angular/forms": "^8.2.9",
    "@angular/http": "^7.2.4",
    "@angular/language-service": "^8.2.9",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "^8.2.9",
    "@angular/platform-browser-dynamic": "^8.2.9",
    "@angular/router": "^8.2.9",
    "@ng-bootstrap/ng-bootstrap": "~4.2.1",
    "@progress/kendo-angular-buttons": "^4.1.0",
    "@progress/kendo-angular-l10n": "^1.2.0",
    "@progress/kendo-angular-pdf-export": "^1.0.4",
    "@progress/kendo-drawing": "^1.5.3",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/lodash": "4.14.107",
    "@types/node": "~6.0.60",
    "ack-angular-fx": "^2.1.2",
    "codelyzer": "^4.0.1",
    "core-js": "^2.4.1",
    "crypto-js": "^4.0.0",
    "file-saver": "^1.3.8",
    "gulp": "^4.0.0",
    "hammerjs": "^2.0.8",
    "husky": "^0.14.0",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~6.3.16",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.1.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "ng-simple-slideshow": "^1.2.2",
    "ngx-device-detector": "1.3.15",
    "primeng": "^5.2.7",
    "protractor": "~5.1.2",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.2.2",
    "secure-web-storage": "^1.0.2",
    "ts-node": "^10.7.0",
    "tslint": "~5.9.1",
    "tslint-html-report": "^2.0.2",
    "typescript": "~3.5.3",
    "zone.js": "^0.9.1"
  }

angular.json test block: -

"test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
              "src/assets/javascript/script.js"
            ],
            "styles": [
              "src/assets/css/styles.css",
              "src/assets/css/bootstrap.css",
              "src/assets/css/toggle-switch-px.css",
              "src/assets/css/fonts-slate.css",
              "node_modules/primeng/resources/themes/omega/theme.css",
              "node_modules/primeng/resources/primeng.min.css",
              "node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ]
          }
        }

Provide some help around this.

I did tried multiple things and came to the conclusion that It was due to non-compatible libraries with karma & jasmine.

Previous package.json: -

"karma": "~6.3.16",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.1.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",

Updated the package.json with following dependencies versions and the error was gone.

"karma": "~6.3.16",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "2.1.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"jasmine-core": "2.99.1",
"jasmine-spec-reporter": "~4.2.1"

Also, if you face such issue, you can also try setting up a new angular project and check the packages versions automatically written by angular in your package.json file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM