blackRose
blackRose

Reputation: 180

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.

Upvotes: 5

Views: 9623

Answers (2)

Carlos Gregorio
Carlos Gregorio

Reputation: 506

I had similar issue and I used "npm run test" instead and that worked for me.

In my case it was an amateur mistake but that's how you learn i guess.

Upvotes: 1

DJClayworth
DJClayworth

Reputation: 26856

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.

Upvotes: 1

Related Questions