Based on your comment, I think you do not need expect($scope.$on).toHaveBeenCalledWith(...); because it ensures that something is really listening for the event.
To claim that an event has been fired, you must prepare everything you need and then complete the action leading to the broadcast of the events. I assume that the specification can be described as follows:
it('should fire "event:auth-loginRequired" event in case of 401', function() { var flag = false; var listener = jasmine.createSpy('listener'); scope.$on('event:auth-loginRequired', listener); $httpBackend.when('GET', myApi.config.apiRoot + '/user').respond(401, ''); runs(function() { myApi.get(function(error, success) {
source share