我想用karma为测试Angular控制器注入$ location。我怎么能这样做?
我试着这样做:
beforeEach(inject(function($injector) {
location = $injector.get('$location');
}));
但出现以下错误:
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 39.0.2171 (Linux)]: Connected on socket D6SQ4moOGrqQyP3i7ulo with id 18222568
LOG: 'Angular-Devise Intercepter'
Chrome 39.0.2171 (Linux) MyApp controllers GameCtrl should to create "testVar" variable with value "test text" FAILED
TypeError: undefined is not a function
at $LocationProvider.$get (/home/nazar/cardgame/app/bower_components/angular/angular.js:11292:34)
at Object.invoke (/home/nazar/cardgame/app/bower_components/angular/angular.js:4182:17)
at /home/nazar/cardgame/app/bower_components/angular/angular.js:4000:37
at Object.getService [as get] (/home/nazar/cardgame/app/bower_components/angular/angular.js:4141:39)
at Object.<anonymous> (/home/nazar/cardgame/app/assets/test/CtrlSpec.js:79:34)
at Object.invoke (/home/nazar/cardgame/app/bower_components/angular/angular.js:4182:17)
at Object.workFn (/home/nazar/cardgame/app/bower_components/angular/angular-mocks.js:2177:20)
Error: Declaration Location
at window.inject.angular.mock.inject (/home/nazar/cardgame/app/bower_components/angular/angular-mocks.js:2162:25)
at Suite.<anonymous> (/home/nazar/cardgame/app/assets/test/CtrlSpec.js:78:20)
at Suite.<anonymous> (/home/nazar/cardgame/app/assets/test/CtrlSpec.js:6:5)
at /home/nazar/cardgame/app/assets/test/CtrlSpec.js:4:1
Chrome 39.0.2171 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.096 secs / 0.073 secs)