title: How do I unit test $scope.broadcast, $scope.$on using Jasmine
body: <p>I'm newbie to AngularJs/NodeJs world, so forgive if this is a basic question to some.</p>
  
  <p>So in a nutshell I've two controllers, the first controller <code>$broadcast</code> an 'Id'  and the second controller fetches that Id with <code>$on</code> and then passes that Id to an intermediate <code>service</code>, which makes an <code>$http</code> ajax call and returns a single <code>Book</code> object. </p>
  
  <p>How do I unit test $scope.broadcast, $scope.$on using Jasmine</p>
  
  <h2>firstCtrl</h2>
  
  <pre><code>.controller('firstCtrl', function($scope, ...){
      $scope.selectGridRow = function() {
          if($scope.selectedRows[0].total !=0)
              $scope.$broadcast('id', $scope.selectedRows[0].id);//Just single plain ID
      };
  });
  </code></pre>
  
  <h2>secondCtrl</h2>
  
  <pre><code>.controller('secondCtrl',
      function($scope, bookService) {
          $scope.$on('id', function(event, id) {
              bookService.getBookDetail(id).then(function(d) {
                  $scope.book = d.book;
              });
          });
      });
  </code></pre>
  
  <h2>expected Json obj</h2>
  
  <pre><code>var arr = "book" : [ {
              "id" : "1",
              "name" : "Tomcat",
              "edition" : "9.1"
             }
            ]
  </code></pre>
  
  <p>Let me know if anyone wants me to post the <code>$http</code> service that's used by the second controller. </p>
  
  <h2>expected behavior</h2>
  
  <p>So from the top of my head, ideally, I would like to test every possible scenario, but something like below, which can then expend:</p>
  
  <pre><code>expect(scope.book).toEqual(arr);
  expect(scope.book).not.toEqual(undefined);
  </code></pre>
  
  <p>Thanks everyone!</p>