0

나는 테스트를 작성하고자하는 angularJS 응용 프로그램의 일부로 작성된 REST 클라이언트를 가지고 있습니다. Jasmine ($ httpBackend에서 패스 스루 사용)을 시도했지만 실제 엔드 포인트와 통화 할 수는 없었습니다 (요구 사항 임).

누가 이것을 허용하는 합리적인 도서관을 알고 있습니까? 또는 재 스민과 레슬링을하는 방법이 있습니까?

+0

그냥 백엔드 나머지 API를 테스트하고 싶다면 – user3232739

+0

을 가진 E2E 테스트로 테스트 할 수 – MarkoCen

+1

클라이언트에서 서버로 실제 HTTP 요청을 테스트하려면 $ httpBackend를 사용할 필요가 없습니다. 실제 엔드 포인트를 요청한 jasmine에서 테스트를 작성했습니다. Jasmine은 비동기 테스트를 지원하므로 실제 나머지 API와 통신하는 테스트를 작성하는 것은 문제가되지 않습니다. – thadam

답변

0

은 먼저 $의 httpbackend에게

describe('MyController', function() { 
var $httpBackend, $rootScope, createController, authRequestHandler; 

// Set up the module 
    beforeEach(module('MyApp')); 

    beforeEach(inject(function($injector) { 
// Set up the mock http service responses 
$httpBackend = $injector.get('$httpBackend'); 
// backend definition common for all tests 
authRequestHandler = $httpBackend.when('GET', '/auth.py') 
         .respond({userId: 'userX'}, {'A-Token': 'xxx'}); 

// Get hold of a scope (i.e. the root scope) 
$rootScope = $injector.get('$rootScope'); 
// The $controller service is used to create instances of controllers 
var $controller = $injector.get('$controller'); 

createController = function() { 
    return $controller('MyController', {'$scope' : $rootScope }); 
}; 
    $httpBackend.when('GET', "/api/rest/").respond(data_to_respond); 
    })); 

다음 쓰기 테스트 케이스

를 주입 할 필요가
it('getTypes - should return 3 car manufacturers', function() { 
     service.getTypes().then(function(response) { 
      //expect will be here 
     }); 
     $httpBackend.flush(); 
    }); 
당신은 당신이 경우 왜 모카를 사용하지 않는 각도기 또는 뭔가 다른
+0

제 질문에서 저는 응답을 가짜로 만들고 싶지 않습니다. 제 고객이 실제 서버와 대화하기를 바랍니다. – Fallso

+0

테스트가 가능하지 않을 때 테스트 할 때 –

+0

위장해야 할 필요가없는 다른 테스트 프레임 워크가 있는지 물어 봅니다. 재스민의 한계라고 확신했기 때문에 – Fallso

관련 문제