Angular Jasmine 测试错误 - $injector 未定义
Angular Jasmine tests error - $injector is not defined
在项目中使用 Karma Im 回填测试(其他人编写了 angular 应用程序 - 我有 'pleasure')...
用 coffeescript 编写的项目。
我有以下茉莉花测试:
'use strict'
describe 'module:file:controller', () ->
$controller = null
$scope = null
$state = null
$stateParams = null
Page = null
File = null
beforeEach (module 'forge')
beforeEach inject(($rootScope, _$controller_, _$state_, _$stateParams_, _Page_, _File_) ->
$scope = $rootScope.$new()
$state = _$state_
$stateParams = _$stateParams_
Page = _Page_
File = _File_
$controller = _$controller_
)
describe 'init', () ->
controller = null
beforeEach () ->
$state = {}
$stateParams = {}
controller = $controller('fileController', {$scope: $scope, $state: $state, $stateParams: $stateParams, Page: Page, File: File})
it 'should set page title to File', () ->
spyOn(Page, 'title')
expect(Page.title).toHaveBeenCalledWith 'Files'
it 'should do something with delete', () ->
spyOn(Page, 'addAlert')
$scope.delete(1)
expect(Page.addAlert).toHaveBeenCalled()
这是控制器:
forge.controller 'fileController', ($scope, $state, $stateParams, Page, File) ->
# Inject base controller
$injector.invoke BaseController, this, { $scope: $scope, Factory: File }
# Set page title
Page.title 'Files'
console.log $stateParams
console.log $state
# Delete
$scope.delete = (id) ->
Page.addAlert 'success', '[TEST] Deleting file...'
console.log $stateParams
console.log $state
# Delegate actions
switch $stateParams.action
when 'delete' then $scope.delete $stateParams.id
我有一堆单元测试 运行ning 很好。该应用程序是使用 g运行t 构建的,所有代码都编译成 /dist/assets/js/app.js.
我的业力配置:
module.exports = (config) ->
config.set
files: [
'../../dist/assets/js/app.js'
'../../bower_components/angular-mocks/angular-mocks.js'
'unit/**/**.test.coffee'
'../module/**/test/unit/**/*.unit.coffee'
]
preprocessors:
'unit/**/**.test.coffee': ['coffee']
'../module/**/test/unit/**/*.unit.coffee': ['coffee']
frameworks: ['jasmine']
reporters: ['progress']
browsers: ['Chrome', 'Firefox', 'Safari']
logLevel: 'ERROR'
jasmineNodeOpts:
onComplete: null
isVerbose: false
showColors: true
includeStackTrace: false
defaultTimeoutInterval: 30000
当我 运行 我收到的测试:
Chrome 48.0.2564 (Mac OS X 10.11.3) module:file:controller init should set page title to File FAILED
ReferenceError: $injector is not defined
at new <anonymous> (/Users/usr1/repos/proj/dist/assets/js/forge.js:75397:3)
at Object.instantiate (/Users/usr1/repos/proj/dist/assets/js/forge.js:14449:14)
at /Users/usr1/repos/proj/dist/assets/js/forge.js:19700:28
at /Users/usr1/repos/proj/bower_components/angular-mocks/angular-mocks.js:2170:12
at Object.<anonymous> (/Users/usr1/repos/proj/src/module/file/test/unit/controller/file-controller.unit.js:25:27)
Expected spy title to have been called with [ 'Files' ] but it was never called.
at Object.<anonymous> (/Users/usr1/repos/proj/src/module/file/test/unit/controller/file-controller.unit.js:35:33)
Chrome 48.0.2564 (Mac OS X 10.11.3) module:file:controller init should do something with delete FAILED
ReferenceError: $injector is not defined
at new <anonymous> (/Users/usr1/repos/proj/dist/assets/js/forge.js:75397:3)
at Object.instantiate (/Users/usr1/repos/proj/dist/assets/js/forge.js:14449:14)
at /Users/usr1/repos/proj/dist/assets/js/forge.js:19700:28
at /Users/usr1/repos/proj/bower_components/angular-mocks/angular-mocks.js:2170:12
at Object.<anonymous> (/Users/usr1/repos/proj/src/module/file/test/unit/controller/file-controller.unit.js:25:27)
TypeError: $scope.delete is not a function
at Object.<anonymous> (/Users/usr1/repos/proj/src/module/file/test/unit/controller/file-controller.unit.js:39:23)
Chrome 48.0.2564 (Mac OS X 10.11.3): Executed 63 of 63 (2 FAILED) (1.155 secs / 1.134 secs)
检查了所有路径并且控制器存在于构建的 app.js 文件中。
现在不知道为什么这个消息仍然存在,任何指示都会很好。
我的应用程序被缩小了 - 这会阻止它工作。
在项目中使用 Karma Im 回填测试(其他人编写了 angular 应用程序 - 我有 'pleasure')...
用 coffeescript 编写的项目。
我有以下茉莉花测试:
'use strict'
describe 'module:file:controller', () ->
$controller = null
$scope = null
$state = null
$stateParams = null
Page = null
File = null
beforeEach (module 'forge')
beforeEach inject(($rootScope, _$controller_, _$state_, _$stateParams_, _Page_, _File_) ->
$scope = $rootScope.$new()
$state = _$state_
$stateParams = _$stateParams_
Page = _Page_
File = _File_
$controller = _$controller_
)
describe 'init', () ->
controller = null
beforeEach () ->
$state = {}
$stateParams = {}
controller = $controller('fileController', {$scope: $scope, $state: $state, $stateParams: $stateParams, Page: Page, File: File})
it 'should set page title to File', () ->
spyOn(Page, 'title')
expect(Page.title).toHaveBeenCalledWith 'Files'
it 'should do something with delete', () ->
spyOn(Page, 'addAlert')
$scope.delete(1)
expect(Page.addAlert).toHaveBeenCalled()
这是控制器:
forge.controller 'fileController', ($scope, $state, $stateParams, Page, File) ->
# Inject base controller
$injector.invoke BaseController, this, { $scope: $scope, Factory: File }
# Set page title
Page.title 'Files'
console.log $stateParams
console.log $state
# Delete
$scope.delete = (id) ->
Page.addAlert 'success', '[TEST] Deleting file...'
console.log $stateParams
console.log $state
# Delegate actions
switch $stateParams.action
when 'delete' then $scope.delete $stateParams.id
我有一堆单元测试 运行ning 很好。该应用程序是使用 g运行t 构建的,所有代码都编译成 /dist/assets/js/app.js.
我的业力配置:
module.exports = (config) ->
config.set
files: [
'../../dist/assets/js/app.js'
'../../bower_components/angular-mocks/angular-mocks.js'
'unit/**/**.test.coffee'
'../module/**/test/unit/**/*.unit.coffee'
]
preprocessors:
'unit/**/**.test.coffee': ['coffee']
'../module/**/test/unit/**/*.unit.coffee': ['coffee']
frameworks: ['jasmine']
reporters: ['progress']
browsers: ['Chrome', 'Firefox', 'Safari']
logLevel: 'ERROR'
jasmineNodeOpts:
onComplete: null
isVerbose: false
showColors: true
includeStackTrace: false
defaultTimeoutInterval: 30000
当我 运行 我收到的测试:
Chrome 48.0.2564 (Mac OS X 10.11.3) module:file:controller init should set page title to File FAILED
ReferenceError: $injector is not defined
at new <anonymous> (/Users/usr1/repos/proj/dist/assets/js/forge.js:75397:3)
at Object.instantiate (/Users/usr1/repos/proj/dist/assets/js/forge.js:14449:14)
at /Users/usr1/repos/proj/dist/assets/js/forge.js:19700:28
at /Users/usr1/repos/proj/bower_components/angular-mocks/angular-mocks.js:2170:12
at Object.<anonymous> (/Users/usr1/repos/proj/src/module/file/test/unit/controller/file-controller.unit.js:25:27)
Expected spy title to have been called with [ 'Files' ] but it was never called.
at Object.<anonymous> (/Users/usr1/repos/proj/src/module/file/test/unit/controller/file-controller.unit.js:35:33)
Chrome 48.0.2564 (Mac OS X 10.11.3) module:file:controller init should do something with delete FAILED
ReferenceError: $injector is not defined
at new <anonymous> (/Users/usr1/repos/proj/dist/assets/js/forge.js:75397:3)
at Object.instantiate (/Users/usr1/repos/proj/dist/assets/js/forge.js:14449:14)
at /Users/usr1/repos/proj/dist/assets/js/forge.js:19700:28
at /Users/usr1/repos/proj/bower_components/angular-mocks/angular-mocks.js:2170:12
at Object.<anonymous> (/Users/usr1/repos/proj/src/module/file/test/unit/controller/file-controller.unit.js:25:27)
TypeError: $scope.delete is not a function
at Object.<anonymous> (/Users/usr1/repos/proj/src/module/file/test/unit/controller/file-controller.unit.js:39:23)
Chrome 48.0.2564 (Mac OS X 10.11.3): Executed 63 of 63 (2 FAILED) (1.155 secs / 1.134 secs)
检查了所有路径并且控制器存在于构建的 app.js 文件中。
现在不知道为什么这个消息仍然存在,任何指示都会很好。
我的应用程序被缩小了 - 这会阻止它工作。