Reputation: 103
I have written test cases in the spec files for several components but when I run ng-test
it is still showing me "Incomplete: no specs found, , randomized with seed ######"
. my karma file looks like this
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
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 // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/tenms'),
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
});
};
and the entry test.ts
file in src folder looks like this
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
there are a couple of spec files in the project for different components. some of them contain some errors. is it being unable to find the spec files because of the errors because some files in the spec files were imported using relative paths? what should I do to fix this problem? thanks in advance
Upvotes: 1
Views: 2031
Reputation: 103
Got an answer. I had to correct all errors in the spec.ts files to avoid compile-time errors. after that everything ran properly.
Upvotes: 3
Reputation: 59
There may be any compiler error which is causing Karma Runner to Stop or you can look for your test.ts file as follows-
// Then we find all the tests. const context = require.context('./', true, /.spec.ts$/);
make sure to allow all spec.ts here.
Upvotes: 1