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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With