我的karma.conf.coffee
是:
module.exports = (config) ->
config.set
basePath: '../../'
preprocessors:
'**/*.coffee': ['coffee']
files: [
'dist/assets/vendor.js'
'public/bower_components/angular-mocks/angular-mocks.js'
'dist/assets/app.js'
'test/public/**/*.coffee'
]
singleRun: true
frameworks: ['mocha']
browsers: ['PhantomJS']
reporters: ['story']
logLevel: config.LOG_INFO
coffeePreprocessor:
options:
bare: true
sourceMap: false
transformPath: (path) ->
path.replace(/\.coffee$/, '.js')
vendor.js
是angular.js
,angular-route.js
和angular-strap.js
的串联js。 app.js
是我连接的所有角度代码。
我有一个测试:test/public/controllers/login.spec.coffee
看起来像:
(->
describe 'Login Controller', ->
beforeEach module 'myApp
it 'should initialize the controller', ->
# createController()
# $scope.init()
)()
当我进行测试时,我得到:
PhantomJS 1.9.7 (Mac OS X) - Login Controller:
PhantomJS 1.9.7 (Mac OS X) "before each" hook: [object Object] FAILED
PhantomJS 1.9.7 (Mac OS X): Executed 1 of 1 (1 FAILED) ERROR (0.005 secs / 0 secs)
PhantomJS 1.9.7 (Mac OS X)
PhantomJS 1.9.7 (Mac OS X) Login Controller "before each" hook: [object Object] FAILED
TypeError: 'undefined' is not an object (evaluating 'fn.call')
我做错了什么?
答案 0 :(得分:2)
看起来你错过了收尾报价...
(->
describe 'Login Controller', ->
beforeEach module 'myApp' // <------ here you forgot it
it 'should initialize the controller', ->
# createController()
# $scope.init()
)()
答案 1 :(得分:1)
(->
describe 'Login Controller', ->
beforeEach module 'myApp
it 'should initialize the controller', ->
# createController()
# $scope.init()
)()
你错过了'after myApp
beforeEach module 'myApp'
始终预览您的coffeescript