2014-10-07 3 views
1

똑바로 보이지만, 내가 $httpBackend을 사용하든 아니든, 결코 반환하지 않습니다!

describe('R', function(){ 
     var Res, http, item, original = {name:"John"}; 
     beforeEach(function() { 
     module('app'); 
     inject(function ($httpBackend, $resource) { 
      http = $httpBackend; 
      Res = $resource('/api/user/:user', {user:'@id'}); 
     }); 
     }); 
     beforeEach(function (done) { 
     http.when('GET','/api/user/1').respond(original); 
     console.log("I GET CALLED"); 
     Res.get({id:'1'},function (res) { 
      console.log("I NEVER GET CALLED"); 
      item = res; 
      done(); 
     }); 
     }); 
     it('should just be true', function(){ 
     expect(true).toBe(true); 
     }); 
}); 

왜 두 번째 console.log 라인 호출 만나지 않는다?

+0

어쩌면 비동기하고 $ 자원 전에 테스트 종료 요청을 완료 할 수 있기 때문에? – originof

+0

나는 소원한다. 필자는 jasmine 2.0과 mocha를 사용하여이 두 가지를 시도했으며, 둘 다'beforeEach (function (done) {}) '구문을 지원합니다. 두 팀 모두 테스트에서 2000 밀리 초의 제한 시간을 초과합니다. 그것은 결코 응답하지 않습니다! – deitch

+0

jasmine.Ajax.withMock 기능 또는 jasmine.createSpy 기능을 사용해보십시오. – originof

답변

1

알겠습니다. Untold 시간은 이것을 알아 내는데 소요되었습니다 (OK, jsfiddle가 때때로 "선언되지 않은 변수를 설명하는"오류를내는 타이밍 문제로 많은 문제가 있음). 한마디로 :

http.when('GET','/api/user/1').respond(original); 
    console.log("I GET CALLED"); 
    Res.get({id:'1'},function (res) { 
     console.log("I NEVER GET CALLED"); 
     item = res; 
     done(); 
    }); 
    http.flush(); 

한숨 ...