get リクエストを実行するファクトリがあります。テストしたいと思います。残念ながら、カルマ テストは、$httpBackend で定義された応答がないことを示しています。
AngularJs 1.2.14、ジャスミン 2.0、カルマ 0.12.0
テストしたいモジュールは次のとおりです。
var appFactory = angular.module('appFactory', []);
appFactory.factory('boxListService', function($http){
return{
getList: function(){
return $http.get('/boxlist').then(function(result){
return result.data;
});
}
};
});
私のテストはこれです:
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();
}));
});
メッセージ:
Error: No response defined !
at $httpBackend (D:/nodeJS/host/test_app/src/public/js/libs/angular/angular-mock.js:1206:13)