2014-09-15 7 views
0

그래서이 내 설치되어 테스트 :이 elbService.remove_instance을 실행할 때기본 각도 서비스를 확인

(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(); 
     }); 

    }) 

    }) 

})(); 

그래서 (1,1) 정의되지 않은 반환

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; 
    }); 
    } 
}); 

가 여기 내 자스민 테스트 파일입니다 . 어떤 아이디어?

+2

그나마 당신이'뿐만 아니라 당신의'$ http' 요청 객체를 return'해야합니다

a = function() { function() { return 1; }() // 1 is visible here }() // ... but not here 

이 바이올린을 참조하십시오이므로, 문제는 하나의 수준이 아닌 두 가지를 반환하고 있습니다 : 'return $ http.delete ("/ api/v1/amazon_' – tymeJV

+0

아 나는 거기에 오타가 있었는데, 나는 그것을 업데이트했다. 다시 서비스를 보길 바래 ... 특별히 함수를 돌려주지는 않겠지 만 왜 내가 해야할지 모르겠다. –

답변

1

@tymeJV에서 언급했듯이 $ http 객체도 반환하거나 범위 변수를 응답과 동일하게 설정해야합니다. http://jsfiddle.net/v80dLmwz/

+0

그래서 기본적으로 http $ .delete() 요청 전에 return이라는 단어를 추가했는데 모두 수정되었다. –

관련 문제