2016-11-15 3 views
0

다음 코드를 테스트하기 위해 httpBackend를 조롱했습니다.

beforeEach(function(){ 
     angular.mock.module(function(ApiProvider) { 
     ApiProvider.setUrl('http://localhost:10010'); 
     }); 
    }); 

    beforeEach(inject(function($rootScope, $controller, _$interval_, $q, $injector, $httpBackend){ 
    $rootScope = $injector.get('$rootScope'); 
    scope = $rootScope; 
    httpBackend = $httpBackend; 

    createController = function() { 
     return $controller('MyCtrl',{ 
     $scope: scope, 
     $uibModalInstance: modalInstance, 
     $interval: _$interval_, 
     }); 
    } 
    })); 

내가 그 엔드 포인트에 POST를 수행 할 때 내가 어떤 응답을받지 못했습니다있는 IT

 httpBackend 
     .when('POST', 'http://localhost:10010/endpoint/action/') 
      .respond(200, mockedResponse); 

내부의

self.Api.post('/endpoint/action/', actionData) 
    .then(function(resp){ 
     result = _.get(resp, 'data.MessageList'); 
     if(resp.status = 200 && result) { 
     for (var i = 0; i < result.length; i++) { 
      addResultMessage(result[i]); 
     } 
     } 
    }); 

나는 다음을 수행 내 서비스를 조롱. 난 그저 내가 지금처럼 시험 후() 어떤 인공 호흡기 콜백에게

답변

0

당신은 호출해야 플러시하지 않는 오류가 발생하지 않습니다

it('should read expired login data', inject(function(authSrvc) { 
    $httpBackend.expectGET('data/auth.json').respond(200, mockedResponse); 

    authSrvc.checkStatus().then(function(data){ 
     expect(authSrvc.isValidSession()).toEqual(false); 
    }); 

    $httpBackend.flush(); 
    })); 
+0

아니, 마지막에 플러시를 추가 작동하지 않습니다. – acostela