2014-02-11 39 views
19

我采用了棱角分明完整的堆栈发展不可用,我karma.conf.js文件角模块噶茉莉花试运行

files: [    
    'app/bower_components/jquery/jquery.js', 
    'app/bower_components/angular/angular.js', 
    'app/bower_components/angular-mocks/angular-mocks.js', 
    'app/bower_components/angular-cookies/angular-cookies.js', 
    'app/bower_components/angular-resource/angular-resource.js', 
    'app/bower_components/angular-route/angular-route.js', 
    'app/bower_components/angular-sanitize/angular-sanitize.js', 
    'app/bower_components/angular-scenario/angular-scenario.js', 
    'app/scripts/controllers/*.js', 
    'app/scripts/directives/*.js', 
    'app/scripts/services/*.js', 
    'app/scripts/app.js', 
    'lib/routes.js',   
    'test/karma/unit/**/test.spec.js'  
], 

测试规格:

'use strict'; 

(function() { 
describe('App', function() { 

    describe('TestController', function() { 

     beforeEach(function() { 
      this.addMatchers({ 
       toEqualData: function(expected) { 
        return angular.equals(this.actual, expected); 
       } 
      }); 
     }); 

     // Load the controllers module 
     beforeEach(module('ratefastApp')); 

     // Initialize the controller and a mock scope 
     var TestController, 
      mockUserResource, 
      scope, 
      $httpBackend, 
      $routeParams, 
      $location; 

     // The injector ignores leading and trailing underscores here (i.e. _$httpBackend_). 
     // This allows us to inject a service but then attach it to a variable 
     // with the same name as the service. 

     beforeEach(
      inject(function($controller, $rootScope, _$location_, _$routeParams_, _$httpBackend_) { 
      scope = $rootScope.$new(); 
      TestController = $controller('TestController', { 
       $scope: scope 
      }); 
      $routeParams = _$routeParams_; 
      $httpBackend = _$httpBackend_; 
      $httpBackend.when('GET', '/api/test/page/:pagenum') 
       .respond([{title: 'test'}]); 
      $location = _$location_; 

     })); 
    }); 
}); 
}); 

在运行上面我得到$injector:nomod Module is not available

回答

0

此错误表示未找到某个模块。具体来说,source for loader.js似乎表明,如果您未注册angular.module模块,则会引发此错误。你有没有这样做ratefastApp?这里的复制来源:

if (!requires) { 
     throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " + 
     "the module name or forgot to load it. If registering a module ensure that you " + 
     "specify the dependencies as the second argument.", name); 
    } 

而且,既然你试图注入$controller, $rootScope, _$location_, _$routeParams_, _$httpBackend_,与模拟$inject,我会确保你有一个包含这些服务在您的karma.conf.js files指令文件开始。您可能还想使用通配符来包含所有角度文件。

45

模块需要在应用程序的其余部分之前加载到你的karma文件中。

这是因为“当模块尚未定义时调用没有依赖关系数组的angular.module会导致此错误被抛出”docs.angularjs.org。因此,您必须在应用程序的其余部分之前明确加载文件。

在你Karma.config JavaScript文件:

'app/bower_components/jquery/jquery.js', 
    'app/bower_components/angular/angular.js', 
    'app/bower_components/angular-mocks/angular-mocks.js', 
    'app/bower_components/angular-cookies/angular-cookies.js', 
    'app/bower_components/angular-resource/angular-resource.js', 
    'app/bower_components/angular-route/angular-route.js', 
    'app/bower_components/angular-sanitize/angular-sanitize.js', 
    'app/bower_components/angular-scenario/angular-scenario.js', 

    'app/scripts/app.js',  // Load your module before the rest of your app. 

    'app/scripts/controllers/*.js', 
    'app/scripts/directives/*.js', 
    'app/scripts/services/*.js', 
    'lib/routes.js',   
    'test/karma/unit/**/test.spec.js'