2017-03-21 14 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']; 
関連する問題