컨트롤러 내 함수에 대한 단위 테스트를 작성하고 있습니다.
이 함수는 $ yyy-MM-dd 형식의 날짜 형식을 지정하기 위해 $ 필터를 사용합니다.
그러나 필터를 사용하는 라인 이후에 내 카르마 스크립트가 실행되지 않습니다.
describe('Validating functions within Controller', function() {
var scope, ctrl, filter, localServiceConvertISODate;
beforeEach(inject(function($controller, $rootScope, $filter, serviceConvertISODate) {
scope = $rootScope.$new(),
ctrl = $controller('MyController', {
$scope: scope,
filter : $filter,
serviceConvertISODate : localServiceConvertISODate
});
}));
it('should test my function', function() {
var dateTo = new Date("22 Sep 2014");
console.log("********* dateTo = " + dateTo);
var myDate = $scope.myDate;
console.log("********* myDate = " + myDate);
var searchdate = (filter('date')(myDate, 'yyyy-MM-dd'));
console.log("searchdate after filter = " + searchdate);
searchdate = localServiceConvertISODate.convertDate(searchdate);
});
});
I을 통해 볼 수있다 : 위의 예에서
$scope.myFunction = function (someDate) {
var dateTo = new Date(someDate);
var myDate = $scope.myDate;
// Code fails after line below on unit test /////
var searchdate = (filter('date')(myDate, 'yyyy-MM-dd'));
searchdate = serviceConvertISODate.convertDate(searchdate);
}
, VAR의 MyDate가 = 1,405967947000 (EPOC 포맷)
단위 테스트 : 여기
는 함수의 내 기록 :
dateTo is returning the correct new date
myDate is returning the correct myDate
그러나 다음 줄 (필터)을 적용하면 테스트가 중단되고 오류가 발생하지 않습니다.
답장을 보내 주셔서 감사합니다. 그러나 나는 테스트에 새로운 것이므로 어포 그리기입니다. 코드 스 니펫을 제공 할 수 있습니까? TypeError : 'undefined'는 ('$ filter ('date ')'를 평가하는) 함수가 아닙니다. –
[AngularJS의 단위 테스트에 대한 개발자 가이드] (https://docs.angularjs.org/guide/unit-testing)를 읽으셨습니까? 나는 당신의 코드에서'$ filter'를 사용하고'filter'를 모두 제거함으로써 시작할 것입니다. – hon2a
필터를 제거하고 var searchdate = ($ filter ('date') (myDate, 'yyyy-MM-dd'))); 내가 오류가 발생했습니다 ReferenceError : 변수를 찾을 수 없습니다 : $ filter –