내 앱용 단위 테스트를 작성하려고합니다. 제 경우에는 http 요청 전화가 들어 있습니다.단위 테스트에서 http 요청을 확인하는 방법은 무엇입니까?
테스트 파일
'use strict';
describe('Controller: testCtrl', function() {
// load the controller's module
beforeEach(module('myApp'));
var testCtrl, scope, $httpBackend;
beforeEach(inject(function (_$controller_, _$rootScope_, _$httpBackend_, $cookies) {
scope = _$rootScope_.$new();
$httpBackend = _$httpBackend_;
testCtrl = _$controller_('testCtrl', {
$scope: scope,
});
}));
it("should return product data", function() {
$httpBackend.whenGET('/api/store/' + productID + '/products').respond([{
//not sure what I should do next...
}])
})
컨트롤러 파일
$http.get(('/api/store/' + productID + '/products').success(
function(data) {
//the data could contain 10 objects with 10+ property within each object.
}
);
HTTP 요청은 매우 복잡한 개체를 반환하기 때문에, 나는 내 테스트를 작성하는 방법을하지 확신합니다. 아무도 그것에 대해 나를 도울 수 있습니까? 고마워요!