测试包裹$ http angularjs

时间:2015-06-26 11:20:59

标签: angularjs ngboilerplate

我正在使用angularjs,我必须测试包裹的$ http

ang.factory("HttpService", ["$http", "$q", function ($http, $q) {
return {
get: function (url) {
  var result = $q.defer();
  $http.get(url).success(function ($data) {
    result.resolve($data);
  }).error(function ($data) {
    result.reject($data);
  });
  return result.promise;
}
 };
}]);

我认为测试应该像

beforeEach(module('ngBoilerplate.employee', function ($provide) {
  HttpService = jasmine.createSpyObj("HttpService", ["get", "post"]);

  $provide.value("HttpService", HttpService);
}));  

beforeEach(inject(function (_$controller_, _$rootScope_, _HttpService_) {
  $scope = _$rootScope_.$new();
  HttpService = _HttpService_;
  $controller = _$controller_('EmployeeCtrl', {$scope: $scope, HttpService: HttpService});
}));

PS:我正在使用ngBoilerplate。 感谢

0 个答案:

没有答案