【发布时间】:2015-06-13 15:07:44
【问题描述】:
我根据Angular unit-testing documentation 中的示例编写了一个简短的单元测试。我试图创建一个没有运气的jsfiddle,所以请多多包涵。
# app definition
app = module 'myApp', []
.controller 'myCtrl', ['$scope', ($scope) ->$scope.foo = 'foo']
# test
describe 'myCtrl tests', () ->
beforeEach module 'myApp'
$controller = undefined
beforeEach inject (_$controller_) ->
$controller = _$controller_
describe 'myCtrl', () ->
it 'should not throw an error', () ->
$scope = {}
controller = $controller 'myCtrl',{$scope: $scope}
expect ($scope.foo).toEqual 'foo'
当我运行这个测试时,我得到“TypeError: undefined is not a function” 对于 $scope.foo 并且测试失败。
【问题讨论】:
标签: angularjs unit-testing coffeescript jasmine karma-jasmine