2
votes

I am trying to test in karma, yet every time I run Karma I get the same error:

$ karma start karma.conf.js --single-run

31 07 2018 12:56:48.134:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/

31 07 2018 12:56:48.138:INFO [launcher]: Launching browser Chrome with unlimited concurrency

31 07 2018 12:56:48.144:INFO [launcher]: Starting browser Chrome

31 07 2018 12:56:49.890:INFO [Chrome 67.0.3396 (Windows 10.0.0)]: Connected on socket 2we1ypnXUlTXv5IRAAAA with id 14298953

Chrome 67.0.3396 (Windows 10.0.0): Executed 0 of 0 ERROR (0.006 secs / 0 secs)

my (mostly) auto-generated karma.conf.js located one level above the tests at: C:\Users\king\Desktop\_REPOS\inventivangular\src

// Karma configuration
// Generated on Tue Jul 31 2018 12:30:22 GMT-0400 (Eastern Daylight Time)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: 'C:/Users/king/Desktop/_REPOS/inventivangular/src/',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      './app/*.component.ts',
      './app/*spec.ts'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  })
}

File path of files to test: C:\Users\king\Desktop\_REPOS\inventivangular\src\app

enter image description here

1

1 Answers

1
votes

Wound up just running ng test from C:\Users\king\Desktop\_REPOS\inventivangular which generated its own karma.conf.js and everything worked.

If you are using auto-generated tests you may need to:

import { HttpClientTestingModule } from '@angular/common/http/testing' 

and

imports: [HttpClientTestingModule]