我在使用Angular (使用Angular-Mock)、Jasmine和CoffeeScript进行单元测试时遇到了问题。
具体地说,这段代码会中断:
'use strict'
describe 'sample suite', ->
beforeEach inject(($rootScope, $compile) ->
scope = $rootScope.$new()
)
it 'should be true', ->
expect('foo').toBe('foo')导致角度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()角度模拟方法一起使用不能与CoffeeScript编译器一起正常工作。
遗憾的是,用return结束beforeEach块并不起作用。
感谢您的帮助。
发布于 2016-11-22 20:41:33
如果你看一下你的两个代码工作和不工作,你会注意到很大的不同
在第一个代码块中,beforeEach接受inject作为参数,而在工作中,您将匿名函数beforeEach ->作为参数传递,这就是为什么会出现错误Error: [ng:areq] Argument 'fn' is not a function, got Object的原因
'use strict'
describe 'sample suite', ->
beforeEach ->
inject ($rootScope, $compile) ->
scope = $rootScope.$new()
it 'should be true', ->
expect('foo').toBe('foo')https://stackoverflow.com/questions/40626775
复制相似问题