get 요청을 실행하는 공장이 있으므로 시험하고 싶습니다. 불행히도 카르마 테스트는 $ httpBackend에 정의 된 응답이 없다는 것을 알려줍니다.AngularJS 재스민 테스트 요청 받기
AngularJS와 1.2.14, 재스민 2.0, 카르마 0.12.0
여기에 내가 원하는 내 모듈의 테스트에 :
describe('Module-Test', function() {
beforeEach(module('appFactory'));
it('should call $http.get in getList', inject(function (boxListService, $httpBackend){
$httpBackend.expectGET('/boxlist');
boxListService.getList();
$httpBackend.flush();
}));
});
:
var appFactory = angular.module('appFactory', []);
appFactory.factory('boxListService', function($http){
return{
getList: function(){
return $http.get('/boxlist').then(function(result){
return result.data;
});
}
};
});
내 시험이있다
메시지 :
Error: No response defined !
at $httpBackend (D:/nodeJS/host/test_app/src/public/js/libs/angular/angular-mock.js:1206:13)
나는 응답이 expectGET에 선언되어야한다는 것을 깨닫기 전에 이것을 약 5 번 보았다. 나는 whenGET이 응답을 선언하는 것이 필요한 유일한 곳이라는 인상을 받고있었습니다. whenGET과 expectGET 둘 다에 응답을 선언해야한다고 말하는 것이 안전합니까? – binarygiant