I am using angular cli version 1.4.5 and below is the karma.conf.ts file
module.exports = function (config) {
config.set({
basePath: '',
exclude: [
"src/app/components/panel/panel.component.spec.ts",
"src/app/components/accordion/accordion.component.spec.ts"
],
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.DEBUG,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
and I even added the exclude in the tsconfig.spec.json file to exclude to pick those files for test.
{
.....,
"include": [
"**/*.spec.ts",
"**/*.d.ts"
],
"exclude": [
"app/components/panel/panel.component.spec.ts",
"app/components/accordion/accordion.component.spec.ts"
]
}
is that am missing something to add for exclusion ?
Running ng test command executes all test spec files of an angular project. if you have a my.component.spec.ts that you want to exclude a component test file Let’s configure the my.component.spec.ts spec file to skip test case execution in test.js
An environment to run angular tests is being created using all the imports at the beginning of the file. TestBed is a powerful unit testing tool provided by angular, and it is initialized in this file. Finally, karma loads all the test files of the application matching their names against a regular expression.
Let’s get started testing an Angular component with the Jasmine test framework. Karma is a test runner tool, it creates a browser instance, run tests to provide the expected results. The benefit of using Karma is that it can be operated via command line and It refreshes the browser automatically whenever we make even minor changes in our app.
It includes excluding a single or group of spec files from jasmine and mocha with the karma test runner. In my previous post, You learned different ways to [run a one spec.ts test case] (/angular-run-single-testfile) an Angular app.
Change the config in the src/test.ts
.
const context = require.context('./', true, /\.spec\.ts$/);
https://github.com/angular/angular-cli/issues/9026#issuecomment-354475734
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