You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a controller that uses the $location service
'use strict';/** * @ngdoc function * @name categoryManagerApp.controller:CategoryCtrl * @description * # CategoryCtrl * Controller of the categoryManagerApp */angular.module('categoryManagerApp').controller('CategoryCtrl',['$scope','$location',function($scope,$location){$scope.go=function(path){$location.path(path);};}]);
Inject the service in 3 steps
'use strict';describe('Controller: CategoryCtrl',function(){// load the controller's modulebeforeEach(module('categoryManagerApp'));varCategoryCtrl,scope,$location;// <-- Step 1 Instantiate the variable.// Initialize the controller and a mock scopebeforeEach(inject(function($controller,$rootScope,_$location_){scope=$rootScope.$new();$location=_$location_;// <-- Step 2 Inject the service and set it to the variable.CategoryCtrl=$controller('CategoryCtrl',{$scope: scope,$location: $location// <-- Step 3 Set it in the mocked controller.// place here mocked dependencies});}));it('should attach a function called go to the scope',function(){vargo=function(path){$location.path(path);};expect(scope.go).toBeDefined();expect($location).toBeDefined();expect(typeof(scope.go)).toBe('function');expect(scope.go.toString()==go.toString()).toBe(true);});});
Instantiate the $location variable.
Inject the _$location_ service and set it to the variable.