[英]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.