2

this codelab에서 튜토리얼을 완료하고 단위 테스트에서 오류를 수정하려고 시도 했으므로 하지만이 오류를 해결하는 방법을 모르겠습니다. 나는 이미이 질문을 보았다 : running-tests-with-localstorage 그러나 그것은 내 문제를 해결하지 못한다.Yeoman의 Angular.js 코드 랩 - 테스트 수정

여기 내 테스트 파일입니다 :

'use strict'; 

describe('Controller: MainCtrl', function() { 

    // load the controller's module 
    beforeEach(function(){ 
    module('mytodoApp'), 
    module('LocalStorageModule') 
    }); 

    var MainCtrl, 
    scope; 

    // Initialize the controller and a mock scope 
    beforeEach(inject(function ($controller, $rootScope) { 
    scope = $rootScope.$new(); 
    MainCtrl = $controller('MainCtrl', { 
     $scope: scope 
    }); 
    })); 

    it('should have no items to start', function() { 
    expect(scope.todos.length).toBe(0); 
    }); 
}); 

그리고 여기에 콘솔 출력 :

PhantomJS 1.9.7 (Linux) Controller: MainCtrl should have no items to start FAILED 
     Error: [$injector:modulerr] Failed to instantiate module mytodoApp due to: 
     Error: [$injector:modulerr] Failed to instantiate module LocalStorageModule due to: 
     Error: [$injector:nomod] Module 'LocalStorageModule' 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. 
     http://errors.angularjs.org/1.2.16/$injector/nomod?p0=LocalStorageModule 
      at /home/ubuntu/mytodo/bower_components/angular/angular.js:1613 
      at ensure (/home/ubuntu/mytodo/bower_components/angular/angular.js:1535) 
      at module (/home/ubuntu/mytodo/bower_components/angular/angular.js:1823) 
      at /home/ubuntu/mytodo/bower_components/angular/angular.js:3781 
     http://errors.angularjs.org/1.2.16/$injector/modulerr?p0=LocalStorageModule&p1=Error%3A%20%5B%24injector%3Anomod%5D%20Module%20'LocalStorageModule'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.16%2F%24injector%2Fnomod%3Fp0%3DLocalStorageModule%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1613%0A%20%20%20%20at%20ensure%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1535)%0A%20%20%20%20at%20module%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1823)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A3781 
      at /home/ubuntu/mytodo/bower_components/angular/angular.js:3810 
     http://errors.angularjs.org/1.2.16/$injector/modulerr?p0=mytodoApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20Failed%20to%20instantiate%20module%20LocalStorageModule%20due%20to%3A%0AError%3A%20%5B%24injector%3Anomod%5D%20Module%20'LocalStorageModule'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.16%2F%24injector%2Fnomod%3Fp0%3DLocalStorageModule%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1613%0A%20%20%20%20at%20ensure%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1535)%0A%20%20%20%20at%20module%20(http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A1823)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A3781%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.16%2F%24injector%2Fmodulerr%3Fp0%3DLocalStorageModule%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520Module%2520'LocalStorageModule'%2520is%2520not%2520available!%2520You%2520either%2520misspelled%2520the%2520module%2520name%2520or%2520forgot%2520to%2520load%2520it.%2520If%2520registering%2520a%2520module%2520ensure%2520that%2520you%2520specify%2520the%2520dependencies%2520as%2520the%2520second%2520argument.%250Ahttp%253A%252F%252Ferrors.angularjs.org%252F1.2.16%252F%2524injector%252Fnomod%253Fp0%253DLocalStorageModule%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A8080%252Fbase%252Fbower_components%252Fangular%252Fangular.js%253F7dcf1b25480258d399759429338cedc57239f2d1%253A1613%250A%2520%2520%2520%2520at%2520ensure%2520(http%253A%252F%252Flocalhost%253A8080%252Fbase%252Fbower_components%252Fangular%252Fangular.js%253F7dcf1b25480258d399759429338cedc57239f2d1%253A1535)%250A%2520%2520%2520%2520at%2520module%2520(http%253A%252F%252Flocalhost%253A8080%252Fbase%252Fbower_components%252Fangular%252Fangular.js%253F7dcf1b25480258d399759429338cedc57239f2d1%253A1823)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A8080%252Fbase%252Fbower_components%252Fangular%252Fangular.js%253F7dcf1b25480258d399759429338cedc57239f2d1%253A3781%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fbase%2Fbower_components%2Fangular%2Fangular.js%3F7dcf1b25480258d399759429338cedc57239f2d1%3A3810 
      at /home/ubuntu/mytodo/bower_components/angular/angular.js:3810 
PhantomJS 1.9.7 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.04 secs/0.006 secs) 
Warning: Task "karma:unit" failed. Use --force to continue. 

Aborted due to warnings. 

UPDATE : 대답 추가는.

여기 내 karma.conf.js 파일이 수정되었습니다. 모듈 angular-local-storage.js를 파일 목록에 추가해야했습니다.

// list of files/patterns to load in the browser 
    files: [ 
     'bower_components/angular/angular.js', 
     'bower_components/angular-mocks/angular-mocks.js', 
     'bower_components/angular-animate/angular-animate.js', 
     'bower_components/angular-cookies/angular-cookies.js', 
     'bower_components/angular-resource/angular-resource.js', 
     'bower_components/angular-route/angular-route.js', 
     'bower_components/angular-sanitize/angular-sanitize.js', 
     'bower_components/angular-touch/angular-touch.js', 
     'bower_components/jquery/dist/jquery.js', 
     'bower_components/jquery-ui/jquery-ui.js', 
     'bower_components/angular-ui-sortable/sortable.js', 
     'bower_components/angular-local-storage/angular-local-storage.js', 
     'app/scripts/**/*.js', 
     'test/mock/**/*.js', 
     'test/spec/**/*.js' 
    ], 
+1

오류는 'LocalStorageModule' 모듈을 로딩하면,이 모듈을 포함하고있는 파일을 카르마 설정에 포함 시켰습니까? – klyd

+0

정확합니다. 나는 그 모듈을 Karma.conf.js 파일에 추가하는 것을 완전히 잊었다. 올바른 것으로 표시 할 수 있도록 답변으로 게시하십시오. – ThiagoPonte

답변

3

karama.conf.js 파일은 files 배열이 포함되어 있습니다. 테스트 할 때, 부양 모든 모듈을 포함하는 파일이 배열에 삽입되어 있는지 확인 :

files: [ 
    /* file paths */ 
] 

또 다른 좋은 점은 파일 구역 patterns를 지원한다는 것입니다. 앞으로이 문제를 피하는 한 가지 방법은 모든 모듈 또는 필요한 스크립트를 한 곳 또는 하나의 공용 폴더에 넣고 패턴을 사용하여 모두로드하는 것입니다.

files: [ 
    /* or whatever other pattern you want to use */ 
    '/myProject/scripts/vendor/*.min.js', 
    '/myProject/scripts/modules/*.min.js', 
    /* the use of ** will search any child folder for the file pattern */ 
    '/myProject/scripts/tests/**/*.js' 
]