나는 테스트를 작성하고자하는 angularJS 응용 프로그램의 일부로 작성된 REST 클라이언트를 가지고 있습니다. Jasmine ($ httpBackend에서 패스 스루 사용)을 시도했지만 실제 엔드 포인트와 통화 할 수는 없었습니다 (요구 사항 임).
누가 이것을 허용하는 합리적인 도서관을 알고 있습니까? 또는 재 스민과 레슬링을하는 방법이 있습니까?
나는 테스트를 작성하고자하는 angularJS 응용 프로그램의 일부로 작성된 REST 클라이언트를 가지고 있습니다. Jasmine ($ httpBackend에서 패스 스루 사용)을 시도했지만 실제 엔드 포인트와 통화 할 수는 없었습니다 (요구 사항 임).
누가 이것을 허용하는 합리적인 도서관을 알고 있습니까? 또는 재 스민과 레슬링을하는 방법이 있습니까?
은 먼저 $의 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();
});
당신은 당신이 경우 왜 모카를 사용하지 않는 각도기 또는 뭔가 다른
그냥 백엔드 나머지 API를 테스트하고 싶다면 – user3232739
을 가진 E2E 테스트로 테스트 할 수 – MarkoCen
클라이언트에서 서버로 실제 HTTP 요청을 테스트하려면 $ httpBackend를 사용할 필요가 없습니다. 실제 엔드 포인트를 요청한 jasmine에서 테스트를 작성했습니다. Jasmine은 비동기 테스트를 지원하므로 실제 나머지 API와 통신하는 테스트를 작성하는 것은 문제가되지 않습니다. – thadam