使用Mocha,Chai,Sinonjs进行测试时,Angular未定义错误

时间:2016-01-25 10:31:37

标签: angularjs unit-testing coffeescript mocha

我的问题在于我试图在角度范围内测试控制器。这是控制台在运行命令mocha --compilers coffee:coffee-script/register **/*.spec.coffee以运行项目中的所有测试文件时向我抛出的错误。

  angular.module('weaver.ui.app');
  ^
ReferenceError: angular is not defined

我最近添加了angular-mocks库,确保angular不是一个未解决的变量,但这并不能解决问题。

我的测试文件的开头看起来像这样(代码编写的是CoffeeScript)

# angular = require 'angular'
angular.module 'weaver.ui.app'

chai = require 'chai'
sinon = require 'sinon'

如果我取消注释require角度,则错误会变为以下内容,因此我认为这不是正确的方法。

\npm\node_modules\angular\angular.js:29016
})(window, document);
   ^

ReferenceError: window is not defined

如果我完全删除了行angular.module 'weaver.ui.app',我会收到类似的错误,但这个错误与控制器有关。

  angular.module('weaver.ui.app').controller('AppDesignSidebarNewcontentCtrl', function($rootScope, $scope) {});
  ^

ReferenceError: angular is not defined

我希望这里有人可以帮助我解决这个问题,这个问题现在已经困扰了我一段时间。

请不要根据控制器的名称判断我;)

0 个答案:

没有答案