首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >意外请求: GET在$httpBackend处不需要更多请求

意外请求: GET在$httpBackend处不需要更多请求
EN

Stack Overflow用户
提问于 2013-11-05 07:51:24
回答 1查看 24K关注 0票数 19

我在我的作用域中有一个函数,用于在用户单击按钮时检索服务的状态,或者当某个事件被触发时自动调用此函数。

这是我的函数,在我使用的控制器中定义:

代码语言:javascript
复制
$scope.getStatus = function() {
  $http({method: 'GET', url: config.entrypoint + config.api + '/outbound/service/' + $scope.serviceId})
    .success(function(data) {
      $scope.errorMessage = '';
      $scope.serviceAllGood = data;
    })
    .error(function() {
      $scope.serviceAllGood = '';
      $scope.errorMessage = 'We are experiencing problems retrieving your service status.';
    });
  }

单元测试是这样进行的:

代码语言:javascript
复制
describe('SendServiceCtrl', function(){
    var scope, ctrl, $httpBackend, configuration;

    beforeEach(function () {
      module('papi', 'ngUpload');
    });

    beforeEach(inject(function(_$httpBackend_, $rootScope, $controller, config) {
      configuration = config;
      $httpBackend = _$httpBackend_;
      $httpBackend.expectGET(configuration.entrypoint + configuration.api + "/user/outboundstatus/").respond(200, {"meta":{"apiVersion":"0.1","code":200,"errors":null},"response":{"allowed":false}});
      scope = $rootScope.$new();
      ctrl = $controller('SendServiceCtrl', {$scope: scope});
  }));

  it('Should get the status', function() {

    scope.serviceId = '09bb5943fa2881e1';
    scope.getStatus();
    $httpBackend.whenGET(configuration.entrypoint + configuration.api + '/outbound/service/' + scope.serviceId).respond(200, {"meta":{"apiVersion":"0.1","code":200,"errors":null}});

  });

});

在单元测试中,我还在同一个控制器上进行了其他$httpBackend测试,但所有这些测试都工作得很好。我做错了什么?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19779528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档