title: Cannot read property '$broadcast' of undefined in AngularJS Jasmine Unit Test
body: <p>I am getting error while writing Angular JS Jasmine Unit Test cases:-</p>
  
  <p><strong>Cannot read property '$broadcast' of undefined</strong></p>
  
  <p>My Code:-</p>
  
  <pre><code>    $scope.$on('getVersionData', function (event, data) {
      getVersion(data.RegistrationId, data.FacilityCode);
  });
  </code></pre>
  
  <p>My UnitTest Code</p>
  
  <pre><code>    beforeEach(inject(function ($rootScope, $injector) {
      $scope = $rootScope.$new();
      $rootScope = $injector.get('$rootScope');
      spyOn($rootScope, '$broadcast').and.callThrough();
      $controller = $injector.get('$controller');
  
  }));
  it('Controller: getVersion: Checking if $scope variable set to expectedValues', function () {
      $rootScope('getVersionData', [{ RegistrationId: 7946531, FacilityCode: 'L' }]);
      expect($rootScope.$broadcast).toHaveBeenCalledWith('getVersionData', [{ RegistrationId: 7946531, FacilityCode: 'L' }]);
  
  
  });
  </code></pre>
  
  <p>Please help with code.</p>