0
AngularJS 컨트롤러 LoginController에 대한 단위 테스트를 만드는 방법? 이 예제에서 AuthenticationService를 모형화하는 방법은 무엇입니까? 내 컨트롤러가 목업을 사용하여 단위 테스트 &에 맞게 올바르게 빌드되어 있습니까?AngularJS에서 컨트롤러에 대한 단위 테스트를 만드는 방법
컨트롤러 인 LoginController 코드 :
layoutControllers.controller('LoginController',
['$scope', '$rootScope', '$location', 'AuthenticationService',
function ($scope, $rootScope, $location, AuthenticationService) {
AuthenticationService.ClearCredentials();
$scope.login = function() {
$scope.dataLoading = true;
AuthenticationService.Login($scope.email, $scope.password, function (response) {
AuthenticationService.SetCredentials($scope.email, $scope.password, response.UserId);
$scope._showValidationErrors(null, null);
$location.path('/');
}, function (response) {
$scope._showValidationErrors(response.Errors, response.OtherErrors);
});
$scope.dataLoading = false;
};
$scope._showValidationErrors = function (errors, otherErrors) {
$scope.validationErrors = [];
$scope.errors = {};
$scope.errors.form = {};
if (errors && angular.isArray(errors)) {
for (var errorCounter in errors) {
$scope.validationErrors.push(errors[errorCounter].Message);
$scope.errors.form[errors[errorCounter].Key] = errors[errorCounter].Message;
}
// debugger;
}
if (otherErrors && angular.isArray(otherErrors)) {
for (var errorCounter2 in otherErrors) {
$scope.validationErrors.push(otherErrors[errorCounter2]);
}
}
}
}]);
내 지식 :)에서 테스트를 실행하지 않습니다 :). AUthentication 서비스를 조롱하는 것은 어떨까요? 아니 cerdentails 설정합니다. 그것은 작동하지 않습니다 :) –
이것은 실제 코드 인 'login()'함수를 테스트 할 것입니다. $ scope 나 $ location 등의 다른 객체에 영향을 줄 수 있습니다. 테스트중인 단위로 정확히 무엇을 고려하고 있는지 설명 할 수 있습니까? – bhantol
Authetnication 서비스는 어떻습니까? 그것은 의존입니다. 나는 컨트롤러 만 테스트하기 위해 조롱 받아야한다고 생각했다. 그러나 나는 틀릴 수도 있습니다. –