2016-09-18 4 views
0

Jasmin/Karma로 AngularJS 코드를 테스트하려고합니다. 나는 또한 MeanJS를 사용하고있다.

Running "karma:unit" (karma) task 
INFO [karma]: Karma v0.12.37 server started at http://localhost:9876/ 
INFO [launcher]: Starting browser Chrome 
INFO [Chrome 53.0.2785 (Linux 0.0.0)]: Connected on socket 8e4tfQKvty6CbglWSqji with id 23318510 
Chrome 53.0.2785 (Linux 0.0.0) My controller greets FAILED 
     Error: [$injector:modulerr] http://errors.angularjs.org/1.5.0/$injector/modulerr?p0=ngMock&p1=Error%3A%20%5B%24injector%3Aunpr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.5.0%2F%24injector%2Funpr%3Fp0%3D%2524%2524asyncCallbackProvider%0A%20%20%20%20at%20Error%20(native)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.min.js%3F0ff025e7c37c0d56654bcf2cc4de18ea50ead3b3%3A6%3A416%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.min.js%3F0ff025e7c37c0d56654bcf2cc4de18ea50ead3b3%3A43%3A7%0A%20%20%20%20at%20Object.d%20%5Bas%20get%5D%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.min.js%3F0ff025e7c37c0d56654bcf2cc4de18ea50ead3b3%3A40%3A270)%0A%20%20%20%20at%20Object.decorator%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.min.js%3F0ff025e7c37c0d56654bcf2cc4de18ea50ead3b3%3A42%3A339)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular-mocks%2Fangular-mocks.js%3F9e9911cea3845a1d5dec76f3cf2dfaa60fd9c669%3A1947%3A12%0A%20%20%20%20at%20Object.invoke%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.min.js%3F0ff025e7c37c0d56654bcf2cc4de18ea50ead3b3%3A41%3A295)%0A%20%20%20%20at%20d%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.min.js%3F0ff025e7c37c0d56654bcf2cc4de18ea50ead3b3%3A39%3A234)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.min.js%3F0ff025e7c37c0d56654bcf2cc4de18ea50ead3b3%3A39%3A358%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A9876%2Fbase%2Fpublic%2Flib%2Fangular%2Fangular.min.js%3F0ff025e7c37c0d56654bcf2cc4de18ea50ead3b3%3A7%3A355) 
      at Error (native) 
      at /home/adrien/Projects/Codowl/Beta-Site/public/lib/angular/angular.min.js:6:416 
      at /home/adrien/Projects/Codowl/Beta-Site/public/lib/angular/angular.min.js:40:60 
      at n (/home/adrien/Projects/Codowl/Beta-Site/public/lib/angular/angular.min.js:7:355) 
      at g (/home/adrien/Projects/Codowl/Beta-Site/public/lib/angular/angular.min.js:39:135) 
      at Object.fb [as injector] (/home/adrien/Projects/Codowl/Beta-Site/public/lib/angular/angular.min.js:43:164) 
      at Object.workFn (/home/adrien/Projects/Codowl/Beta-Site/public/lib/angular-mocks/angular-mocks.js:2464:52) 
     TypeError: $controller is not a function 
      at Object.<anonymous> (/home/adrien/Projects/Codowl/Beta-Site/public/modules/users/tests/account-creation.spec.js:21:20) 
Chrome 53.0.2785 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.017 secs/0.015 secs) 
Warning: Task "karma:unit" failed. Used --force, continuing. 

답변

2

: 여기

'use strict'; 

angular.module('myapp', []) 
    .controller('MyCtrl', ['$scope', function MyCtrl($scope) { 
     $scope.greeting = "hello"; 
    }]); 

describe('My controller', function() { 
    var $controller, $scope; 

    beforeEach(module('myapp')); 

    beforeEach(inject(function($rootScope, _$controller_) { 
     $controller = _$controller_; 
     $scope = $rootScope.$new(); 
    })); 

    it('greets', function() { 
     var controller = $controller('MyCtrl', { 
      $scope: $scope 
     }); 
     expect($scope.greeting).toEqual('hello'); 
    }) 

}); 

및 전체 오류입니다 : 내 테스트를 실행하면 , 나는 다음과 같은 오류 여기

TypeError: $controller is not a function 

에게이 작동하지 않습니다 샘플입니다 내 모서리 가짜 파일이 내 보어 파일의 각도 의존성과 동일한 버전이 아니기 때문에 이런 일이 발생했습니다. 이것은 어려운 것이 었습니다. 'D

관련 문제