How to mock/trigger a $routeChangeSuccess in Angular unit tests?
问题 Given a handler attached to the $routeChangeSuccess event to update the title property on $rootScope: $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { $rootScope.title = 'My title'; }); in unit tests, I expect that performing a route change would update the title property: it('should set a title on $routeChangeSuccess', function () { $location.path('/contacts'); $rootScope.$apply(); expect($rootScope.title).toBe('My title'); }); However, the code in the