In my code snippet, I have a simple function that reloads the current window when $locationChangeSuccess
occurs:
$rootScope.$on('$locationChangeSuccess', function(){
self.window.location.reload();
});
I am looking to test this function using karma. My initial approach was as follows:
beforeEach(inject(function($rootScope) {
rootScope = $rootScope;
}));
it('should reload the window if the URL changes', function() {
spyOn(rootScope, '$on');
rootScope.$broadcast('$locationChangeSuccess');
expect(rootScope.$on).toHaveBeenCalled();
});
I have also attempted using $emit instead of $broadcast, but encountered the same outcome. Does anyone have suggestions on how to make this work?