为什么httpbackend没有工作角?

时间:2016-01-15 11:37:18

标签: angularjs angularjs-directive angularjs-scope jasmine angular-ui-router

我正在尝试使用$ httpBackend测试$ http webservice?我收到了一个错误。如何使用$ httpbackend测试服务?

这是我的代码 http://plnkr.co/edit/S3LFymv8hrxtatWaCv1A?p=preview

it('call http service', function() {

  authRequestHandler = httpBackend.when('GET', 'data.json')
    .respond([{
      "name": "hello"
    }, {
      "name": "hello12"
    }, {
      "name": "hello22"
    }, {
      "name": "hello45"
    }]);

  httpBackend.flush();
  service.callData().then(function(response) {
    console.log(response)
    expect(response.data.length).toBe(4)
  })
})

1 个答案:

答案 0 :(得分:0)

试试这个

authRequestHandler = httpBackend.when('GET', 'data.json')
  .respond([{
    "name": "hello"
  }, {
    "name": "hello12"
  }, {
    "name": "hello22"
  }, {
    "name": "hello45"
  }]);

service.callData().then(function(response) {
  console.log(response)
  expect(response.data.length).toBe(4)
})

httpBackend.flush();