Karma Jasmine:执行0 of 0错误

时间:2015-07-29 18:02:36

标签: angularjs testing jasmine karma-runner

我正在与Karma和Jasmine进行角度测试。在执行karma init并为家庭控制器编写第一个测试后,我不断获得Executed 0 of 0 ERROR。它似乎并没有在文件中被选中。

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

    basePath: '',

    frameworks: ['jasmine'],
    files: [
        'public/assets/libs/angular/angular.min.js',
        'bower_components/angular-mocks/angular-mocks.js',
        'public/app/app.module.js',
        'public/app/app.config.js',
        'public/app/**/*.js',
        'test/unit/**/*.spec.js'
    ],

    exclude: [
    ],

    preprocessors: {
    },

    reporters: ['progress'],

    port: 3030,

    colors: true,

    logLevel: config.LOG_INFO,

    autoWatch: true,

    browsers: ['Chrome'],

    singleRun: false

    }); //config.set
} //module.export

测试(已修复)

describe('HomeController', function() {

//Inject 'app' module into this spec.
beforeEach(module('app'));

//Inject instance of Scope.
var homeController;

beforeEach(inject(function($rootScope, $controller) {
    //create a new scope
    scope = $rootScope.$new();

    //create new controller, using the newly created scope
    HomeController = $controller('HomeController', {
        $scope: scope
    });

}));

//Set expectations
it('the message should say Hello World', function(HomeController) {
    expect(scope.message).toBe('Hello World');
});


});

和HomeController:

(function() {
'use strict';

angular
    .module('app')
    .controller('HomeController', HomeController);

HomeController.$inject = ['$scope', '$log'];

function HomeController($scope, $log) {
    /*jshint validthis: true*/
    var vm = this;

    vm.message = 'Hello World';

} //HomeController()

})(); //Controller

感谢您的帮助。

3 个答案:

答案 0 :(得分:3)

对于那些也遇到“执行0 0错误”问题的人:

以下是如何更好地调试此错误,因为命令行中的日志消息可能被截断或者没有足够的帮助:

在karma的浏览器实例(例如Chrome)中,在以下函数中的karma.js中设置断点: this.error = function (msg, url, line) { 由于将传输到命令行日志的msg的字符串表示形式不是很有帮助,因此请在此处进行分析。

答案 1 :(得分:3)

测试打字稿时遇到同样的问题 - 我在chrome控制台中发现了问题:

拒绝执行' xxx'因为它的MIME类型(' video / mp2t')不可执行。

该修复程序原来是添加

mime: {
  'text/x-typescript': ['ts', 'tsx']
}

进入karma.conf.js。

答案 2 :(得分:2)

我明白了。测试it('...')位于beforeEach()块内,因此有0个测试。它现在位于它自己的独立区块中。