2

Trying to get a similar behavior as in 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' }] })
    ...

Somehow respond() not returns reguestHandler and turns Can not read property 'respond' of undefined'. What am I doing wrong?

Rimian
  • 36,864
  • 16
  • 117
  • 117
fishko
  • 21
  • 1
  • That example is from the docs for version 1.3, which version are you using? You might want the 1.2 branch... https://code.angularjs.org/1.2.23/docs/api/ngMock/service/$httpBackend – ivarni Sep 02 '14 at 05:59
  • You are right, i use `"angular": "1.2.x"`, thanks! – fishko Sep 02 '14 at 07:07

0 Answers0