繁体   English   中英

角Mo和茉莉花-“参数'fn'不是函数,有对象”错误

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM