1

Unit tests:

describe "Lunch controller", ->
  beforeEach module('Lunch')
  beforeEach inject(($httpBackend) ->
    $httpBackend.expectGET('/lunchers')
      .respond(200, ["some content", "some other content"])
  )

  describe "LunchCtrl", ->
    it "should set images to a populated array", inject(($controller, $httpBackend) ->
      scope = {}
      ctrl = $controller("LunchPoolController",
        $scope: scope
      )
      expect(scope.lunchers.length).toBe 2
    )

is throwing

 at /Users/jd/Dropbox/apps/lookingtolunch/spec/javascripts/controller_specs.js.coffee:13
INFO [watcher]: Changed file "/Users/jd/Dropbox/apps/lookingtolunch/spec/javascripts/controller_specs.js.coffee".
Chrome 32.0.1700 (Mac OS X 10.9.1) Lunch controller LunchCtrl should set images to a populated array FAILED
    TypeError: Cannot read property 'length' of undefined
        at null.<anonymous> (/Users/jd/Dropbox/apps/lookingtolunch/spec/javascripts/controller_specs.js.js:13:35)
        at Object.invoke (http://localhost:3000/assets/application.js:7886:19)
        at workFn (http://localhost:3000/assets/application.js:14982:22)
    Error: Declaration Location
        at window.inject.angular.mock.inject (http://localhost:3000/assets/application.js:14970:27)
        at null.<anonymous> (/Users/jd/Dropbox/apps/lookingtolunch/spec/javascripts/controller_specs.js.js:7:57)
        at null.<anonymous> (/Users/jd/Dropbox/apps/lookingtolunch/spec/javascripts/controller_specs.js.js:6:10)
        at /Users/jd/Dropbox/apps/lookingtolunch/spec/javascripts/controller_specs.js.js:1:1
Chrome 32.0.1700 (Mac OS X 10.9.1): Executed 2 of 2 (1 FAILED) (2.766 secs / 0.201 secs)
SomeKittens
  • 38,868
  • 19
  • 114
  • 143
John
  • 1,246
  • 15
  • 34

1 Answers1

0

Assuming LunchPoolController is firing off an HTTP request, you'll need to use $httpBackend.flush() to make sure all requests are going through. (For more, see the Flushing HTTP requests section).

SomeKittens
  • 38,868
  • 19
  • 114
  • 143
  • actually, that controller has a service injected into it, so maybe the issue is that I'm not injecting the service into the controller in these specs ? – John Feb 05 '14 at 06:49