【问题标题】:TypeError: Object #<Object> has no method 'apply' Error: Argument 'fn' is not a function, got Object when running karma/jasmine testsTypeError: Object #<Object> has no method 'apply' Error: Argument 'fn' is not a function, got Object when running karma/jasmine tests
【发布时间】:2013-09-20 20:41:59
【问题描述】:

我正在尝试使用 requireJS、AngularJS、Karma 和 Jasmine 的组合运行测试。

我有一个超级简单的规范,可以进行一些非常基本的测试,但我不断收到以下错误:

TypeError: Object #<Object> has no method 'apply'
Error: Argument 'fn' is not a function, got Object

我的配置文件可以在这里找到:

https://gist.github.com/owzzz/6582481

【问题讨论】:

    标签: angularjs requirejs jasmine require karma-runner


    【解决方案1】:

    改变

    beforeEach(angular.module(settings.appName));   //angular.module() is to recreate a module
    

    beforeEach(module(settings.appName)); //use module() to get the module and then inject to the test
    

    【讨论】:

    • 当我这样做时,我得到ReferenceError: module is not defined。你能建议吗?
    • 我也在这里,所以一种方法得到 OP 错误,然后我做这个改变得到你刚才说的错误。我需要了解如何让我的主要 app.js 和 maincontroller.js 成为一个概念。我们真的让 Angular 框架运行吗?感觉就像我们只是在伪装它——很好,但由于这些错误,它无法正常工作。我在网上找到的任何东西都无法帮助我获得它。
    • @zsong 这里的设置表示是应用的对象还是配置项。
    【解决方案2】:

    您需要参考 angular-mocks.js 以使模块工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      相关资源
      最近更新 更多