0
중첩 된 상태에 대한 단위 테스트를 작성하려고합니다. 상태는 부모 상태에서 일부 범위 요소를 상속받습니다. 내 테스트에서는 분명히 상위 상태를 볼 수 없으므로 상속 된 범위 항목을 볼 수 없습니다.각도 UI 라우터 테스트 범위 상속
it('should show the account page', inject(['$controller', 'security', function ($controller, security){
// set up controller with a scope
var $scope = $rootScope.$new();
// the parent controller calls this
var user = { first: 'First', last: 'Last', email: '[email protected]', gender:'male', hasPassword:true};
$httpBackend.when('GET', '/api/user/current-user').respond(200, user);
$controller('AccountViewCtrl', { $scope: $scope});
$rootScope.$digest();
// verify the initial setup
//scope attributes defined on the parent controller
expect($scope.user).toEqual(user);
expect($scope.account).toEqual(user);
// scope attribute defined on the controller
expect($scope.genders.length).toEqual(2);
expect($scope.editable).toBe(false);
expect($scope.editCheck()).toBe(false);
}]));
AccountCtrl은 모든 하위 상태에서 필요한 요소 수를 정의합니다.
.controller('AccountCtrl', ['$scope', 'security', function ($scope, security){
$scope.user = security.requestCurrentUser();
$scope.account = angular.copy($scope.user);
}])
는 AccountViewCtrl는 다른 원소를 정의하지만 단지 제어기를 인스턴스화하고 부모 상태의 가시성이 없을뿐만
.controller('AccountViewCtrl', ['$scope', function ($scope) {
$scope.editable = false;
$scope.genders = [
{ name: 'Male', value: 'male' },
{ name: 'Female', value: 'female' }
];
$scope.editCheck = function(){
return $scope.editable;
};
....
}])
테스트에 실패한 상위 AccountCtrl의 요소를 상속 관련 요소. ui-router 상태를 테스트하는 최상의 방법이 있습니까?