[angularjs] Angularjs 및 qunit 테스트

[angularjs] Angularjs 및 qunit 테스트

-

좋아요

컨트롤러 대신 이것을 시도하십시오

$controller ( 'RootCtrl' ,[ '$scope' , '$rootScope' , '$location' , '$route' , function ( $scope , $rootScope , $location , $route ) { $scope : this. $scope , $location : this. $location }]);

-------------------

비슷한 문제가 있었으므로 여기에 다른 대답이 없기 때문에.

나는 결국 다음을 사용했습니다.

클라이언트 측 코드 :

var myApp= angular.module( 'myApp' , []); myApp.controller( 'myCtrl' , function ( $scope ) { $scope.canSubmit = function ( ) { return true ; } }

Qunit 테스트 :

var ctrl, ctrlScope, injector; module ( "Testing the controller" , { setup : function ( ) { angular.module( 'myApp' ); injector = angular.injector([ 'ng' , 'myApp' ]); ctrlScope = injector.get( '$rootScope' ).$new(); ctrl = injector.get( '$controller' )( 'myCtrl' , { $scope : ctrlScope }); ctrlScope.model = { }; }, teardown : function ( ) { } }); test( "Given something happened then allow submit" , function ( ) { ok(ctrlScope.someFunction(...), "some functionality happened" ); equal( true , ctrlScope.canSubmit()); });

이 블로그 게시물 이 유용했습니다.

테스트중인 컨트롤러에 더 많은 것을 쉽게 주입 할 수 있습니다.

공유하기 글 요소 저작자표시

출처https://stackoverflow.com/questions/22008778

from http://hotelsdotcom.tistory.com/878 by ccl(A) rewrite - 2021-01-19 09:29:24