2016-08-08 3 views
0

을 반환합니다. 양식 테스트 양식을 작성하고 있습니다. 내 주 템플릿 컨트롤러에서 주입 된 서비스를 조롱하고 있습니다. 그리고 양식 서식 파일에는 동일한 서비스를 주입하는 지시문도 들어 있습니다.

html2js를 사용하여 HTML 템플릿을로드하고 있습니다. 는 그리고 $ 컴파일에이 오류를 던지고있다 :

여기

Error: [$injector:unpr] Unknown provider: CommonServiceProvider <- CommonService

내가 내 테스트를 설정하는 방법입니다

beforeEach(inject(function ($rootScope, $compile, $controller, $q, $filter, $templateCache) { 

    //scope instance to use in test cases. 
    scope = $rootScope.$new(); 

    //set mock 
    var _commonService = MockCommonService($q, $filter).CommonService; 


    //Inject fake service into controller 
    var controller = $controller('PromoCreateGlobalCtrl', {$scope: scope, CommonService: _commonService}); 


    //for my directive tempalte 
    var titleSearchTmplt = $templateCache.get('directives/title-search/title-search.html'); 
    $templateCache.put('app/directives/title-search/title-search.html', titleSearchTmplt); 

    //for my main form template 
    var templateHtml = $templateCache.get('promotion/create/global/promo-global-create.html'); 
    var formElem = angular.element(templateHtml).find('form'); 


    $compile(formElem)(scope); //error is thrown on this line. 

    form = scope.form; 

    scope.$apply(); 

    //directiveElem = getCompiledElement(); 

}));

지침의 컨트롤러에서 모의 ​​서비스를 어떻게로드해야합니까? 그것이 문제의 원인이라고 생각합니다. 누군가 테스트를 위해 같은 케이스로 들어갔습니까?

이 문제는 지시어 템플릿을로드 할 때 두 번째로로드되는 CommonService 때문에 발생하는 것으로 보입니다. 아니면 다른 원인이 있습니까?

답변

0

당신은 beforeeach에 서비스를 주입 할 필요가

var에 CommonService

beforeEach(inject(function ($rootScope, $compile, $controller, $q, $filter, 
$templateCache,_CommonService_){ 
CommonService=_CommonService_;} 
관련 문제