Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine in Angular 2+ No specs found

When I run ng test Karma opens Jasmine in Chrome with the following message:

Incomplete: No specs found

The Karma window looks like so:

Karma window

My karma.conf.js is pretty standard:

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/malbet'),
      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
  });
};

My src/test.ts file is also standard:

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;
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
const context = require.context('./', true, /\.spec\.ts$/);
context.keys().map(context);

Is the error likely to be in these two configuration files or would it be a problem with how I introduce the tests in the component's xxx.spec.ts file?

like image 290
Mike Poole Avatar asked Dec 05 '25 17:12

Mike Poole


1 Answers

I think I've got to the bottom of this. Jasmine was not getting far enough to run the tests because the build included a type error.

I had assumed that such an error would not cause Jasmine to give what looked like a failure. I suppose it did not get round to running any tests. Now that I have corrected the type error Jasmine is returning a list of unit test errors.

like image 182
Mike Poole Avatar answered Dec 07 '25 15:12

Mike Poole