I'm facing a frustrating issue with Karma and Jasmine in my Angular 9 project. Despite setting up the configuration files correctly, I keep getting a "No specs found" message when running ng test
. I have tried various adjustments, including creating dummy test files, but the problem persists.
Here is an overview of my tests folder structure:
spec
services
address.service.spec.ts
login.service.spec.ts
...
support
jasmine.json
My jasmine.json file looks like this:
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js", // also attempted using "**/*[sS]pec.ts"
"services/*[sS]pec.js" // also experimented with "services/*[sS]pec.ts"
],
"helpers": [
"helpers/**/*.js" // also tried "helpers/**/*.ts"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
Additionally, here is a snippet from my karma.conf.js file:
// This is my Karma configuration file
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false,
},
coverageIstanbulReporter: {
dir: require('path').join(
__dirname,
'./coverage/censored',
),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};