2014-05-19 1 views
3

나는 다음과 같이 내 각 응용 프로그램과 webapi 포장 서비스에 대한 호출이 app.run 기능에서 실행되는 초기에 인증을위한 몇 가지 논리를 추가했습니다 :app.run 함수에서 사용되는 조롱 된 각도 서비스를 어떻게 주입합니까?

myApp.run(function ($rootScope, $location, myService) { 

myService.getCurrentUser().then(function (promise) { 
    //reroute to either access denied or the start page when access is verified. 

}); 

// register listener to watch route changes 
$rootScope.$on("$routeChangeStart", function (event, next, current) { 

    //check access 
}); 
}); 

이 내 모든 단위 테스트가 파산 한 후 , 이후 app 모듈을 만들기 전에 myService의 조롱 된 버전을 삽입하는 방법을 모르겠습니다. 필자는 서비스와 조롱 된 서비스를 개별 모듈로 분해하여 실제 앱을 만들기 전에 만들 수 있습니다. 이처럼 : 이것은 그러나 작동하지

angular.mock.module('ServiceModule'); 

    angular.mock.module('EArkivApp', function ($provide, myMockedService) { 
     $provide.value('myService', myMockedService); 
    }); 

, 그것은 "myMockedService는"합니다 (ServiceModule의 일부입니다)를 알 수없는 업체입니다 불평. 이 문제를 해결하는 방법에 대한 좋은 제안이 있습니까?

+0

난 당신에 대한이 문서를 참조 할 수 있습니다 가정에서, 보좌관 비계를 사용하여이 배운을 [ 각진 모듈 지연로드] (http://blog.getelementsbyidea.com/load-a-module-on-demand-with-angularjs/) 도움말 – Rebornix

답변

0


jsfiddle을 제공해 주시겠습니까? 당신이 카르마를 사용하는 경우
한편, 다음은 다음과 같이 사용할 수 있습니다

/*global describe, beforeEach, module, inject, it, expect*/ 
describe('Controller: MyCtrl', function() { 
    'use strict'; 
    // load the controller's module 
    beforeEach(module('myApp')); 

    var MyCtrl, 
     scope, 
     modalInstance; 

    // Initialize the controller and a mock scope 
    beforeEach(inject(function ($controller, $rootScope, myMockedService) { 
    scope = $rootScope.$new(); 
     modalInstance = _$modal_.open({ 
       templateUrl: 'views/my-template.html' 
      }); 
     MyCtrl = $controller('MyCtrl', { 
      $scope: scope, 
      $myMockedService: myMockedService 
     }); 
    })); 

    it('should be true', function() { 
     expect(true).toBe(true); 
    }); 
}); 

내가 곧 길이 :

관련 문제