【问题标题】:Karma Jasmine AngularJS module not definedKarma Jasmine AngularJS 模块未定义
【发布时间】:2016-04-17 09:32:10
【问题描述】:

这个问题似乎被问了很多,但没有一个答案能解决我的问题。

我正在尝试运行 karma-jasmine 测试,看起来像(以下是 mySpec.js 文件)

    describe('Testing', function () {

  beforeEach(module('app'));

  var $controller;

  beforeEach(inject(function(_$controller_){
    $controller = _$controller_;
  }));

  describe('firsttest', function () {

    it('should set the value of First Name', function () {
      var $scope = {};
      var controller = $controller('myCtrl', { $scope: $scope });
      $scope.vm.FirstName = "John Smit";
    }); 


  });

});

在 karma.conf.js 文件中,我的文件部分如下

files: [
  'node_modules/angular/angular.min.js',
  'node_modules/angular-mocks/angular-mocks.min.js',
  'node_modules/angular-resource/angular-resource.min.js',
  'js/dist/allapp.js',
  'js/tests/mySpec.js'
],

无论我做什么,包括在单独的 html 文件中创建纯茉莉花测试或更改文件 [] 我总是得到相同的错误

encountered a declaration exception FAILED
ReferenceError: module is not defined

有什么想法吗?

【问题讨论】:

  • 试试angular.mock.module
  • 我得到的回复是angular.mock.module is not a function
  • 哦,我的 angular-mocks.min.js 应该没有 min 谢谢你让我仔细看看它
  • 模块错误消失了,但现在我又遇到了另一个错误。因为它不能 .getContext 在我的 html 上画布。
  • 好吧,这是另一个问题,与测试无关。 :) 如果您想接受它以结束您的问题,我在第一条评论中发布了答案。

标签: angularjs jasmine karma-jasmine


【解决方案1】:

尝试angular.mock.module() 而不是module()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 2015-09-03
    • 2016-02-26
    • 2015-03-28
    • 2020-01-06
    • 2013-12-20
    相关资源
    最近更新 更多