title: spyOn $scope.$on after $broadcast toHaveBeenCalled fails
body: <p>I'm having a lot of trouble getting this simple test working.</p>
  
  <p>I've got an <code>$scope.$on</code> listener in a controller that I want to test. I just want to make certain it's called after a broadcast event.</p>
  
  <p>To do this, I thought the following code would work:</p>
  
  <pre><code>describe("Testing the parent controller: ", function() {
      var scope, ctrl;
  
      beforeEach(function() {
          module("myApp");
  
          inject(function($rootScope, $controller) {
              scope = $rootScope.$new();
  
              ctrl = $controller('parent-ctrl', {
                  $scope: scope,
              });
          });
      });
  
  
      it ("should trigger broadcast when current page updates", function() {
          spyOn(scope, "$on");
          scope.$broadcast("myEvent", 999);
          expect(scope.$on).toHaveBeenCalled();
      });
  });
  </code></pre>
  
  <p>It doesn't (<code>Expected spy $on to have been called.</code>).  I've dug through numerous examples:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/19352636/how-do-i-test-an-event-has-been-broadcast-">How do I test an event has been broadcast in AngularJS?</a>
  in-angularjs</li>
  <li><a href="https://stackoverflow.com/questions/19441782/how-do-i-test-scope-on-in-angularjs">How do I test $scope.$on in AngularJS</a></li>
  <li><a href="https://stackoverflow.com/questions/15272414/how-can-i-test-events-in-angular">How can I test events in angular?</a></li>
  <li><a href="https://stackoverflow.com/questions/19383607/unit-test-spy-on-emit">unit test spy on $emit</a></li>
  <li><a href="https://stackoverflow.com/questions/25181032/how-do-i-unit-test-scope-broadcast-scope-on-using-jasmine">How do I unit test $scope.broadcast, $scope.$on using Jasmine</a></li>
  <li><a href="https://stackoverflow.com/questions/19441782/how-do-i-test-scope-on-in-angularjs">How do I test $scope.$on in AngularJS</a></li>
  <li><a href="https://stackoverflow.com/questions/16757503/how-can-i-test-broadcast-event-in-angularjs">How can I test Broadcast event in AngularJS</a></li>
  </ul>
  
  <p>and learned a lot, but for some reason I'm just not making some critical connection.</p>
  
  <p>I have noticed that the <code>$on</code> handler does respond post-assertion, which is unhelpful.  I've tried <code>scope.$apply()</code> and <code>.andCallThrough()</code> in various configurations but nothing seems to work.</p>
  
  <p>How is this done?</p>