8
은 내가 $ 필터에 의해 반환되는 방법을 spyOn 다른 스파이를 추가하는 방법을 궁금해
의 코드를 참조하십시오 ('날짜 내부 방법을 AngularJS와 ') 내가 확인할 수 있도록
expect(something, something).toHaveBeenCalledWith('1234', 'dd-MMM-yyyy');
은 내가 $ 필터에 의해 반환되는 방법을 spyOn 다른 스파이를 추가하는 방법을 궁금해
의 코드를 참조하십시오 ('날짜 내부 방법을 AngularJS와 ') 내가 확인할 수 있도록
expect(something, something).toHaveBeenCalledWith('1234', 'dd-MMM-yyyy');
컨트롤러에 전달 된 필터를 조롱하고이 가상에서 스파이를 반환 할 수 있어야합니다. 그런 다음 스파이가 정상적으로 호출되었는지 테스트 할 수 있습니다.
예 :
describe('MyCtrl', function() {
var filter, innerFilterSpy, http, scope;
beforeEach(inject(function ($rootScope, $controller, $http) {
http = $http;
innerFilterSpy = jasmine.createSpy();
filter = jasmine.createSpy().and.returnValue(innerFilterSpy);
scope = $rootScope.$new();
controller = $controller('MyCtrl', {
'$scope': scope,
'$http': http,
'$filter': filter
});
}));
it('call $filter("date") and test()', function() {
expect(scope.date).toBe('01-Jan-1970');
expect(http.get).toHaveBeenCalled();
expect(filter).toHaveBeenCalledWith('date');
expect(innerFilterSpy).toHaveBeenCalledWith('1234', 'dd-MMM-yyyy');
});
});
이 도움이하지만 난 당신이 그것을 사용하지 않기 때문에 $ 필터를 주입하는 오해의 소지가있어 지적하고 싶었습니다. – Alex
감사합니다. 지금 삭제했습니다. – fiznool