好的,这是我的设置:
var app = angular.module("KamajiDash", ['ngResource','ui.bootstrap'.. 'elasticsearch']);
app.service("elbService",function($http) {
this.remove_instance = function(elb_id, instance_id) {
$http.delete("/api/v1/amazon_elbs/"+elb_id+"/remove_instance/"+instance_id).success(function(data){
return data;
}).error(function(error){
return error;
});
}
});
这是我的茉莉花测试文件:
(function(){
var elbService, httpBackend;
describe ('elbService', function(){
beforeEach(function(){
module('KamajiDash');
inject(function(_elbService_,$httpBackend){
httpBackend = $httpBackend;
elbService = _elbService_;
});
});
describe("#remove_instances", function(){
beforeEach(function(){
httpBackend.when("DELETE","/api/v1/amazon_elbs/1/remove_instance/1").respond("success")
})
it("will provide a method called remove instances, that take two args, that calls $http.delete with the correct url", function(){
elbService.remove_instance(1,1).then(function(response){
expect(response).toEqual("success");
});
httpBackend.flush();
});
})
})
})();
所以当我运行这个 elbService.remove_instance(1,1) 时返回未定义。任何想法为什么?