首页 > 解决方案 > Karma 没有运行测试。执行 0 of 0 错误

问题描述

我正在尝试在 karma 中进行测试,但每次运行 Karma 时都会遇到相同的错误:

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

31 07 2018 12:56:48.134:INFO [karma]: Karma v1.7.1 服务器在http://0.0.0.0:9876/开始

2018 年 3 月 7 日 12:56:48.138:INFO [启动器]:以无限并发启动浏览器 Chrome

2018 年 7 月 31 日 12:56:48.144:INFO [启动器]:启动浏览器 Chrome

2018 年 7 月 31 日 12:56:49.890:INFO [Chrome 67.0.3396 (Windows 10.0.0)]: 连接到套接字 2we1ypnXUlTXv5IRAAAA,ID 为 14298953

Chrome 67.0.3396(Windows 10.0.0):执行 0 of 0 错误(0.006 秒/0 秒)

我的(大部分)自动生成的 karma.conf.js 位于测试上方一级: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
  })
}

要测试的文件的文件路径: C:\Users\king\Desktop\_REPOS\inventivangular\src\app

在此处输入图像描述

标签: karma-jasminekarma-runner

解决方案


刚运行就结束了ng testC:\Users\king\Desktop\_REPOS\inventivangular它生成了自己的 karma.conf.js 并且一切正常。

如果您使用自动生成的测试,您可能需要:

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

imports: [HttpClientTestingModule] 

推荐阅读