如何在karmatest中测试用coffeescript编写的angularjs控制器?
我在测试中一直收到以下错误:
TypeError:'undefined'不是/home/rolf/projects/web/stylus/coffee/test/unit/controller.spec.js:8的函数(评估'App.PhoneListCtrl(范围)') p>
我的控制器如下所示:
'use strict'
### Controllers ###
App = App or {}
class App.PhoneListCtrl
constructor: ($scope) ->
$scope.phones = [{
'name':"nexus S"
'snippet': 'Fast just got faster with Nexus S'
},
{'name': "Motorola XOOM®",
'snippet': "The next next generation tablet"
},
{'name': "Motorola XOOM® with WiFi",
'snippet': "The next next generation tablet"
}
]
App.PhoneListCtrl.$inject = ['$scope']
angular.module('app.controllers', []).controller('phoneListCtrl', App.PhoneListCtrl)
我的测试如下:
'use strict'
# jasmine specs for controllers go here
describe 'phoneCat app', ->
beforeEach module('app.controllers')
describe 'phoneListCtrl', ->
it 'should create "phones" model with 3 phones', ->
scope = {}
ctrl = App.PhoneListCtrl(scope)
expect(scope.phones.length).toBe(3)
当我在浏览器中使用此控制器时,它会运行得很好,所以我有点迷路了。 什么是未定义的? 当我不使用
时应用
命名空间,一切正常。 命名空间