Currently, I'm testing an AngularJS controller using Karma. The controller is supposed to inject a $route in order to access the current path. However, when running the karma test, I encounter the following error:
TypeError: 'undefined' is not an object( evaluating '$route.current')
Here is the code for my controller:
angular.module('myApp').controller('EditController',['$scope', '$http', '$route', function($scope,
$http,$route){
var myId = $route.current.params.myId;
$scope.var1 = 'var1';
console.log(myId);
}]);
This is how my Karma file looks like:
'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');
});
});