如何更正此AngularJS Karma测试设置过滤器注入

如何更正此AngularJS Karma测试设置过滤器注入,angularjs,karma-runner,angularjs-filter,Angularjs,Karma Runner,Angularjs Filter,我一直在学习AngularJS,现在是开始编写测试的时候了,但我在第一个障碍上就摔倒了 我的karma配置文件是: module.exports = function(config) { config.set({ basePath: '..', // frameworks to use frameworks: ['mocha'], // list of files / patterns to load in the browser files: [

我一直在学习AngularJS,现在是开始编写测试的时候了,但我在第一个障碍上就摔倒了

我的karma配置文件是:

module.exports = function(config) {
  config.set({
    basePath: '..',

    // frameworks to use
    frameworks: ['mocha'],

    // list of files / patterns to load in the browser
    files: [
      'node_modules/chai/chai.js',
      'public/js/libs/jquery-1.9.1.js',
      'public/js/libs/angular.js',
      'test/libs/angular-mocks.js',
      'public/js/**/*.js',
      'test/angular/**/*.js'
    ],
    exclude: [],
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ['Chrome'],
    captureTimeout: 60000,
    singleRun: false
  });
};
我声明了一个过滤器:

angular.module('timeMachine.filters',[])
  .filter('hours', function() {
  return function(input) {
    return input == 1
      ? '1 hour'
      : input + ' hours';
  }
});
还有一个测试:

var should = chai.should();

describe("The hours filter", function() {

    beforeEach(function() {
      angular.module('timeMachine.filters');
    });

    it('should be able to test', function(){
      true.should.equal(true);
    });

    it('should be able to inject an hours filter', inject(function($filter) {
      var hours = $filter('hours');
      expect(hours).not.to.equal(null);
    }));
});
但是,第二次测试失败,并显示以下消息:


[$injector:unpr]未知提供程序:hoursFilterProvider您应该在测试中使用angular.mock.module。
查看我的答案

我还不太擅长测试,但是egghead.io有一系列关于这方面的教程,可能会有所帮助。啊,我想在angular.js之后加入angular-mocks.js会让我受益匪浅。我很快就会试试这个。。。谢谢如果你来曼彻斯特,我欠你一个拥抱!这非常有效。