title: How do I test $scope.$on in AngularJS
body: <p>How do I test that the scope is populated after the broadcast? I've searched and found a few QA's here in stackexchange, but none answered my problem. The code is working alright, just don't know how to test it. May I add that I'm a novice to testing, and especially with Jasmine.</p>
  
  <p>So, here's the code:</p>
  
  <p>Service CrappySvc:</p>
  
  <pre><code>update: function() {
      $rootScope.$broadcast('updatecrappy', Crappy.query());
  }   
  </code></pre>
  
  <p>Controller GetCrappyCtrl:</p>
  
  <pre><code>  $scope.$on('updatecrappy', function(event, crap) {
      $scope.crap = crap;
    });
  </code></pre>
  
  <p>Jasmine:</p>
  
  <pre><code>beforeEach(inject(function($rootScope, $httpBackend, $controller, Crappy) {
    rootScope = $rootScope;
    scope = $rootScope.$new();
    Crappy = mockCrappy;
  
        ...
    spyOn(rootScope, '$broadcast');
        ...
  
    ctrl = $controller('GetCrappyCtrl', {
    $scope : scope,
    Crappy : mockCrappy
  });               
  </code></pre>
  
  <p>}));</p>
  
  <pre><code>it('$scope.$on should have been triggered', function() {          
    rootScope.$broadcast('updatecrappy', [{id : 2, name : 'crappy'}]);
    expect(rootScope.$broadcast).toHaveBeenCalledWith('updscenes', [{id : 2, name : 'crappy'}]);
  </code></pre>
  
  <p>});</p>
  
  <p>Stone</p>