2017-03-21 3 views
0

AngularJS 유닛 테스팅에서 시작하고 "SiteCtrl"이라는 이름의 컨트롤러가 등록되지 않았습니다.AngularJS - 컨트롤러가 등록되지 않았습니다.

내가 뭘 잘못하고있어?

describe('#hasFormError', function() { 

    var $rootScope,form, templateHtml, ctrl,$scope,scope; 

    angular.module("TestApp"); 
    beforeEach(function() { 
     angular.module("TestApp"); 
    }); 

    beforeEach(inject(function ($rootScope, $controller, $compile, $templateCache) { 
     $scope = $rootScope.$new(); 
     ctrl = $controller; 
     ctrl('SiteCtrl', { $scope: scope }); 

     var a1 = angular.element('<div class="page_container" ng-controller="SiteCtrl"><form name="shan"><div class="zip"><input ng-if="max_length == 5" type="text" name="zipcode" value="" ng-model="Sitezip.zipcode" ng-pattern="/^[0-9]*$/" ng-maxlength="max_length" required><input ng-if="max_length == 7" type="text" name="zipcode" value="" ng-model="store_zip.zipcode" ng-pattern="/^[a-zA-Z0-9]*$/" ng-maxlength="max_length" required></form></div>'); 


     $compile(a1)($scope); 
     form = $scope.shan; 
     $scope.$apply() 


    })); 


    it("TestCase :controller defined \n", function() { 
     expect(ctrl).toBeTruthy(); 
    }); 

    it("TestZipCode", function() { 
     form.zipcode.$setViewValue("4535433123123"); 
     expect(form.zipcode.$valid).toBeTruthy(); 
    }); 


}); 
+0

어떤 오류 메시지가 표시됩니까? –

+0

angular.js에서 10691로 오류가 발생했습니다. – Shan

답변

5

당신은 당신이 그것을 사용할 수 있습니다 그 후 파일 어떤 JS에서 'SiteCtrl'을 주입해야합니다.

app.controller("SiteCtrl",SiteCtrl); 
SiteCtrl.$inject = ['$scope','$state','$filter']; 
관련 문제