这是我的运行块,我在其中rootScope
根据位置路径设置了几个属性:
angular.module('xyz').run(['$rootScope', '$location', '$route', function($rootScope, $location, $route){
$rootScope.brand = $location.path().split('/')[1];
$rootScope.appName = $rootScope.brand.split('.')[2];
});
这是失败的单元测试:
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();
}));
尝试了这些方面的东西:
it('should set the default category to match the category_id found in location.hash', function() {
$browser.setUrl('http://server/#/categories/2');
$browser.poll();
scope.$eval();
$browser.xhr.flush();
expect(ctrl.selectedCategory).toBe('2');
});
没有帮助。