title: Testing broadcasts in AngularJS and Testacular
body: <p>I'm using the <a href="https://github.com/witoldsz/angular-http-auth" rel="nofollow">angular-http-auth</a> module which intercepts 401 responses. This module broadcasts <code>event:auth-loginRequired</code> if there is a 401 response which can be received with $on(). But how can I test this?</p>
  
  <pre><code>beforeEach(inject(function($injector, $rootScope) {
    $httpBackend = $injector.get('$httpBackend');
    myApi = $injector.get('myApi');
    scope = $rootScope.$new();
    spyOn($scope, '$on').andCallThrough();
  }));
  describe('API Client Test', function() {
    it('should return 401', function() {
      $httpBackend.when('GET', myApi.config.apiRoot + '/user').respond(401, '');
      myApi.get(function(error, success) {
        // this never gets triggered as 401 are intercepted
      });
      scope.$on('event:auth-loginRequired', function() {
        // This works!
        console.log('fired');
      });
  
      // This doesn't work
      expect($scope.$on).toHaveBeenCalledWith('event:auth-loginRequired', jasmine.any(Function));
  
      $httpBackend.flush();
    });
  });
  </code></pre>