[英]angular.js:13424 Error: [ng:areq] Argument 'fn' is not a function, got Object
[英]Angular Mocks and Jasmine - “Argument 'fn' is not a function, got Object” error
我在使用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编译器。
beforeEach
块之前都没有return
是行不通的。
任何帮助表示赞赏。
如果您查看两个代码是否有效,您会注意到其中的巨大区别
在工作前的第一个代码块中, 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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.