【发布时间】:2017-03-30 08:02:40
【问题描述】:
我在使用 Angular(使用 Angular-Mocks)、Jasmine 和 CoffeeScript 进行单元测试时遇到问题。
具体来说,这段代码会中断:
'use strict'
describe 'sample suite', ->
beforeEach inject(($rootScope, $compile) ->
scope = $rootScope.$new()
)
it 'should be true', ->
expect('foo').toBe('foo')
导致 Angular debug.html:37 Error: [ng:areq] Argument 'fn' is not a function, got Object 错误。
但这确实有效:
'use strict'
describe 'sample suite', ->
beforeEach ->
sample = 'test'
it 'should be true', ->
expect('foo').toBe('foo')
这意味着使用带有全局 inject() angular-mocks 方法的语法不能与 CoffeeScript 编译器一起正常工作。
遗憾的是,以 return 结尾的 beforeEach 块不起作用。
任何帮助表示赞赏。
【问题讨论】:
-
@TomePejoski 你的意思是不使用通配符吗?没有帮助,我想问题出在 Karma 和 Jasmine 适配器之间。
-
不,it does not。您的测试代码显然与您发布的代码不同。请提供MCVE。这很可能是由于您的 Angular 应用程序中的错误(不正确的
config块左右)而发生的。
标签: javascript angularjs unit-testing coffeescript jasmine