Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No project support the 'test' target in Angular

I want to test Angular project with 'ng test' command, but I'm obtaining error 'No project support the test target. Does anyone know what should I add in project dependencies to run tests with mentioned command? I don't want to create another project just to have those dependencies installed and copy code from existing project. Which libraries should I install? Npm install karma and jasmine is not enough, maybe I should add something in config files, but I don't know what should I add. Any help would be appreciated.

like image 231
blackRose Avatar asked Nov 07 '22 11:11

blackRose


1 Answers

Copying from blackRose's self-answer in comments:

Add something like the following to your angular.json, on the same level as the "build" entry in "architect".

"test": {
  "builder": "@angular-devkit/build-angular:karma",
  "options": {
    "main": "src/test.ts",
    "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.spec.json",
    "karmaConfig": "src/karma.conf.js",
    "stylePreprocessorOptions": {
      "includePaths": [ "src/app/shared/styles"]
    },
    "styles": ["src/styles.scss"],
    "scripts": [],
    "assets": [ "src/favicon.ico", "src/assets", "src/manifest.json"]
  }
}

Also add

"test": "ng test"

to the scripts part of package.json.

like image 115
DJClayworth Avatar answered Nov 15 '22 06:11

DJClayworth