AngularJS inject service mock inside service tests
问题 I have been trying to test a service to no avail for some time now and was hoping for some help. Here is my situation: I have a service looking a little like this myModule.factory('myService', ['$rootScope', '$routeParams', '$location', function($rootScope, $routeParams, $location) { var mySvc = { params: {} } // Listen to route changes. $rootScope.$on('$routeUpdate', mySvc.updateHandler); // Update @params when route changes mySvc.updateHandler = function(){ ... }; ... ... return mySvc; }]);