$ httpBackend响应未定义

时间:2014-09-02 05:55:42

标签: angularjs unit-testing mocking httpbackend

尝试获得与Example

类似的行为

UnitTest.coffee

describe 'Unit: EditAccessController', ->
  ...
  (var $httpBackend, personRequestHandler)   
  personUrl = /\/people\/\d+/
  testPerson = { personId: 123 }
  ...
  beforeEach inject ($injector) ->
    ...
    # Set up the mock http service responses
    $httpBackend = $injector.get '$httpBackend'

    personRequestHandler = $httpBackend.whenGET(personUrl).respond(testPerson)
    console.log(personRequestHandler)  # undefined
    ...

  it 'should ....', ->
    personRequestHandler.respond(404, { errors: [{ message: 'Person not found' }] })
    ...

不知怎的respond()没有返回reguestHandler并且转无法读取未定义'的属性'响应'。我做错了什么?

0 个答案:

没有答案