Here is my run block, where I set a couple of properties on rootScope based on the location path:
angular.module('xyz').run(['$rootScope', '$location', '$route', function($rootScope, $location, $route){ $rootScope.brand = $location.path().split('/')[1]; $rootScope.appName = $rootScope.brand.split('.')[2]; });
Here's a unit test that doesn't work:
beforeEach(module('App')); beforeEach( inject( function( $controller, _$location_, $rootScope) { $location = _$location_; $scope = $rootScope.$new(); AppCtrl = $controller( 'AppCtrl', { $location: $location, $scope: $scope }); })); it('AppCtrl has been initialized', inject( function() { expect( AppCtrl ).toBeTruthy(); }));
Tried something on these lines:
it('should set the default category to match the category_id found in location.hash', function() { $browser.setUrl('http://server/
Did not help.
angularjs unit-testing
Chandra
source share