0
我想測試一個控制器爲angularjs使用業力,控制器注入$路線獲取當前路徑,但是當我嘗試運行業績測試時,我得到。
TypeError: 'undefined' is not an object(evaluating '$route.current')
這裏是我的控制器:
angular.module('myApp').controller('EditController',['$scope', '$http', '$route', function($scope,
$http,$route){
var myId = $route.current.params.myId;
$scope.var1 = 'var1';
console.log(myId);
}]);
這裏是我的噶文件:
'use strict';
describe('Controller: EditController', function(){
beforeEach(module('myApp'));
var EditCtrl,scope,route;
beforeEach(inject(function($controller,$rootScope,$route,$http){
scope=$rootScope.$new();
EditCtrl = $controller('EditCtrl',{
$scope:scope,
$route:route
});
}));
it('should have var1 equal to "var1"',function(){
expect(scope.var1).toEqual('var1');
});
});
小心EditCtrl與EditController不一樣我認爲你不需要注入$ route和$ http – Whisher 2014-09-25 15:56:20