单元测试:
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
)
正在投掷
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)