2017-02-02 7 views
1

나는 카르마 테스트 실행 플랫폼에서 재스민 프레임 워크를 사용하고 있습니다. 나는 API를 테스트하는 것에 완전히 새로운 것이다. 따라서 초기 계획에 따르면 $ httpBackend를 사용하여 $ 응답을 테스트해야합니다. 테스트를 실행할 때마다 실패합니다. 그리고 Webstorm은 다음과 같은 이유로 $ httpBackend 고유 메소드를 강조 표시합니다.

$ httpBackend.verifyNoOutstandingRequest(); 또는 $ httpBackBack.expectGET();

그러나 $ httpBackend.flush() 기능에는 문제가 없습니다. 누가 문제가 될 수 있는지 아는 사람 있습니까? 저는 웹 스톰이 "해결되지 않은 기능"으로 강조 표시하는 부분을 굵게 표시했습니다. 내 테스트 자체 여기

angular.module('myApp').controller('PlanController', function ($rootScope, $scope, UserMetric, $state) { 
$scope.pls = []; 
$scope.plsNames = []; 

$scope.load = function() { 
    $scope.pls = []; 
    $scope.plsNames = []; 
    UserMetric.query(function (result, headers) { 
     for (var i = 0; i < result.length; i++) { 
      $scope.pls.push(result[i]); 
      $scope.plsNames.push(result[i].label) 
     } 

    }); 

}; 
$scope.load(); 

$scope.delete = function (item) { 
    UserMetric.delete({id: item.id}, function() { 
     $scope.load(); 
    }); 
}; 
} 

그리고있다 :

describe('Controller: PlanController', function() { 
beforeEach(module('myApp')); 
beforeEach(module('ui.router')); 

var ctrl, scope, mockUserMetric, $httpBackend; 

beforeEach(inject(function(_$controller_, _$rootScope_, $injector, _UserMetric_, _$httpBackend_) { 
    scope = _$rootScope_.$new(); 
    $httpBackend = _$httpBackend_; 
    mockUserMetric = _UserMetric_; 

    ctrl = _$controller_('PlanController', { 
     $scope: scope 
    }); 
})); 

afterEach(function() { 
    $httpBackend.verifyNoOutstandingExpectation(); 
    $httpBackend.verifyNoOutstandingRequest(); 
}); 

it('Unit test remove plans function in home page', inject(function(UserMetric) { 

    $httpBackend.expectGET('http://localhost:8083/api/v1/plans') 
     .respond(200, [ 
      {label: 'first', id: 1}, 
      {label: 'second', id: 2} 
     ]); 
    var pls = UserMetric.query(); 
    expect(pls.length).toBe(0); 

    $httpBackend.flush(); 

    expect(pls.length).toBe(2); 



})); 
}); 

감사 여기

angular.module('myApp') 
.factory('UserMetric', function ($resource, DateUtils,HOST) { 
    return $resource(HOST+'api/v1/plans/:id', {}, { 
     'query': { method: 'GET', isArray: true}, 
     'get': { 
      method: 'GET', 
      transformResponse: function (data) { 
       data = angular.fromJson(data); 
       return data; 
      } 
     }, 
     'update': { method:'PUT' } 
    }); 
}); 

내 컨트롤러에서 조각입니다 : 여기

내 $ 응답의 조각입니다 당신은 사전에 도움을 청합니다.

+0

그리고 아무도 동정, I에 유래 사회에 희망을 개최했습니다 ... 대답 타이프 라이터 커뮤니티 스텁을 추가하는 방법에 대해 설명합니다. 산타가 존재하지 않는다는 것을 알게되면 실망과 실망을 비교할 수 있습니다. –

+0

WebStorm 2016.3.4에서 같은 문제가 발생합니다. – Wilgert

답변

1

TypeScript 커뮤니티 스텁에서 angular-mocks을 추가해야합니다.

$httpBackend.expectGET/DELETE/...은 표준 각도의 일부가 아닙니다. 그 ngMockE2E

thread보기에 -