我正在尝试为我的控制器编写单元测试。我尝试了以下设置,但没有一个有效:
设置#1:
beforeEach module 'PostApp'
describe 'HomeCtrl', () ->
describe 'test', () ->
it 'does stuff', inject ($controller) ->
console.log $controller
$scope = {}
$scope.test = true
(expect $scope.test).toBe true
设置#2:
beforeEach module 'PostApp'
describe 'HomeCtrl', () ->
$controller = null
beforeEach inject (_$controller_) ->
$controller = _$controller_
describe 'test', () ->
it 'does stuff', () ->
console.log $controller
$scope = {}
$scope.test = true
(expect $scope.test).toBe true
请记住,我要做的就是记录$controller
。这两个设置都抛出了这个错误(根本没有提供信息):
Firefox 37.0.0 (Ubuntu 0.0.0) HomeCtrl test does stuff FAILED
minErr/<@/home/pv/Sites/web/ngbp-coffee/vendor/angular/angular.js:68:12
loadModules/<@/home/pv/Sites/web/ngbp-coffee/vendor/angular/angular.js:4411:15
forEach@/home/pv/Sites/web/ngbp-coffee/vendor/angular/angular.js:336:11
loadModules@/home/pv/Sites/web/ngbp-coffee/vendor/angular/angular.js:4372:5
createInjector@/home/pv/Sites/web/ngbp-coffee/vendor/angular/angular.js:4297:11
workFn@/home/pv/Sites/web/ngbp-coffee/vendor/angular-mocks/angul
值得注意的是module 'PostApp'
返回一个未定义的对象。但是,这是我的应用程序的名称,并且在测试之前正在加载文件。我做错了什么?