2014-02-11 3 views
19

I für die Entwicklung Winkel volle Stapel sind mit, meine karma.conf.js Datei istWinkelmodule nicht in Karma Jasmine Testlauf zur Verfügung

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'  
], 

Test-Spec:

'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_; 

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

auf dem Laufe oben bekomme ich $injector:nomod Module is not available.

Antwort

0

Dieser Fehler zeigt an, dass ein Modul nicht gefunden wird. Insbesondere die source for loader.js scheint zu zeigen, dass dieser Fehler ausgelöst wird, wenn Sie ein Modul mit angular.module nicht registriert haben. Hast du das mit ratefastApp gemacht? Hier ist die kopierte Quelle:

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); 
    } 

Da auch Sie versuchen $controller, $rootScope, _$location_, _$routeParams_, _$httpBackend_ zu injizieren, mit dem Modell $inject, würde ich anfangen, indem sichergestellt wird Sie die Dateien, diese Dienste in Ihrer karma.conf.js files Richtlinie enthält. Sie können auch Platzhalter verwenden, um alle eckigen Dateien aufzunehmen.

45

Die Module müssen vor dem Rest der Anwendung in Ihre Karma-Dateien geladen werden.

Dies liegt daran, dass "Wenn angular.module ohne das Array von Abhängigkeiten aufgerufen wird, wenn das Modul noch nicht definiert wurde, wird dieser Fehler ausgelöst" docs.angularjs.org. Daher müssen Sie die Dateien vor dem Rest Ihrer Anwendung explizit laden.

In Ihren Karma.config Javascript-Dateien:

'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' 
Verwandte Themen