2016-05-02 9 views
1

私のプロジェクトからコントローラをテストしようとしていますが、モジュールが見つかりませんでした。私は同様の質問/回答を見てきましたが、解決策は私のために働いていません。カルマ/ジャスミンを使用している場合、角度モジュールは使用できません

次のように私の角度のコードは次のとおりです。

angular.module('atMain') 
    .controller('MainController', ['$scope', 'atDirApi', 'atServer', '$sce', '$filter','$routeParams', '$location', '$window', 
    function($scope, atDirApi, atServer, $sce, 
     $filter, $routeParams, $location, $window) { 
     /* controller functions attached to $scope here*/ 
    }]); 

私のカルマのテストでは、次のようになります。

describe('', function() { 
    var MainCtrl; 
    beforeEach(module("atMain")); 
    beforeEach(inject(function($controller) { 
     MainCtrl = $controller("MainController"); 
    })); 

    it('should showImage to !showImage', function() { 
     var $scope = {}; 
     var controller = $controller('MainController', { $scope: $scope }); 
     $scope.showImage = false; 
     $scope.showFunc(); 

     expect($scope.showImage).toBe(true); 
    }); 
}); 

マイkarma.confファイルには、次があります。

 files: [ 
     'bower_components/angular/angular.js', 
     'bower_components/angular-route/angular-route.js', 
     'bower_components/angular-mocks/angular-mocks.js', 
     'app.js', 
     'services/server-service/server-service.js', 
     'components/main/main-controller.js', 
     'components/main/main.js', 
     'tests/*.js' 
    ], 

とエラー私は次のようになります:

Uncaught Error: [$injector:nomod] Module 'atMain' 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. 

答えて

2
angular.module('atMain') 

は、既存の角度モジュールを取得します。このように使用すると、モジュールがすでに

angular.module('atMain', [...]) 

に登録する必要がありますこれは$injector:nomodエラーメッセージが言っていることです。

関連する問題