Angular 14.2 unit testing doesn't find spec when running ng test or npm test

Viewed 38

I'm trying for the first time to configure unit testing in my Angular 14 project but i got Incomplete: No specs found, , randomized with seed 69677.

Here's my configurations files

tsconfig.spec.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ],
    "typeRoots": ["node_modules/@types"]
  },
  "files": [
    "src/test.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.spec.ts",
    "src/**/*.d.ts",
  ]
}

package.json

{
  "name": "project-test",
  "version": "0.2.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular-builders/custom-webpack": "^14.0.1",
    "@angular-material-components/color-picker": "^8.0.0",
    "@angular/animations": "^14.2.2",
    "@angular/cdk": "^14.2.2",
    "@angular/common": "^14.2.2",
    "@angular/compiler": "^14.2.2",
    "@angular/core": "^14.2.2",
    "@angular/flex-layout": "^14.0.0-beta.40",
    "@angular/forms": "^14.2.2",
    "@angular/material": "^14.2.2",
    "@angular/platform-browser": "^14.2.2",
    "@angular/platform-browser-dynamic": "^14.2.2",
    "@angular/router": "^14.2.2",
    "@fortawesome/angular-fontawesome": "^0.11.1",
    "@fortawesome/fontawesome-svg-core": "^6.2.0",
    "@fortawesome/free-brands-svg-icons": "^6.2.0",
    "@fortawesome/free-solid-svg-icons": "^6.2.0",
    "@ngx-translate/core": "^14.0.0",
    "@ngx-translate/http-loader": "^7.0.0",
    "angular-star-rating": "^6.0.0",
    "chart.js": "^3.9.1",
    "css-star-rating": "^1.3.1",
    "jsmind": "^0.4.8",
    "json-ignore": "^0.4.0",
    "keycloak-angular": "^12.1.0",
    "keycloak-js": "^18.0.1",
    "ng2-charts": "^4.0.0",
    "ngx-sharebuttons": "^11.0.0",
    "rxjs": "~7.5.6",
    "tslib": "^2.4.0",
    "webpack": "^5.74.0",
    "zone.js": "~0.11.8"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.2.2",
    "@angular/cli": "^14.2.2",
    "@angular/compiler-cli": "^14.2.2",
    "@types/jasmine": "~4.3.0",
    "@types/node": "^14.17.0",
    "brotli-webpack-plugin": "^1.1.0",
    "jasmine": "^4.4.0",
    "jasmine-core": "~4.4.0",
    "karma": "~6.4.1",
    "karma-chrome-launcher": "~3.1.1",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~ 2.0.0",
    "typescript": "~4.7.4"
  }
}

In the console i've got errors but I don't know how to fix them.

ng test

⠹ Generating browser application bundles (phase: setup)...
- @angular/core [es2015/esm2015] (https://github.com/angular/angular.git)
✔ Browser application bundle generation complete.

./src/polyfills.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Emit attempted before Angular Webpack plugin initialization.

./src/test.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Emit attempted before Angular Webpack plugin initialization.

Error: Failed to initialize Angular compilation - Cannot read property 'fileName' of null


20 09 2022 10:33:28.619:WARN [karma]: No captured browser, open http://localhost:9876/
20 09 2022 10:33:28.644:INFO [karma-server]: Karma v6.4.1 server started at http://localhost:9876/
20 09 2022 10:33:28.644:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
20 09 2022 10:33:28.649:INFO [launcher]: Starting browser Chrome
20 09 2022 10:33:29.770:INFO [Chrome 105.0.0.0 (Windows 10)]: Connected on socket LsDl3VzOpNHgg8p_AAAB with id 15088237
20 09 2022 10:33:29.822:WARN [web-server]: 404: /_karma_webpack_/main.js
Chrome 105.0.0.0 (Windows 10): Executed 0 of 0 SUCCESS (0.014 secs / 0 secs)
TOTAL: 0 SUCCESS

How could I fix those console errors ?

0 Answers
Related