title: No $on function on $scope in Angular.js unit tests, but is on $rootScope in test
body: <p>I'm trying to run a simple unit test that just creates a controller (a colleague wrote it, so others could add their own unit tests), however changes I've made are stopping even this from passing. The colleague doesn't know why it's not working. Here is the simple test.</p>
  
  <p><strong>Test</strong>
  </p>
  
  <pre><code>describe("My Controller", function () {
      var $q, $controller, $scope, $rootScope;
      var createCtrl;
      beforeEach(function () {
          module('myModule');
      });
      beforeEach(inject(function (_$q_, _$rootScope_, _$controller_, _$httpBackend_) {
          $controller = _$controller_;
          $scope = _$rootScope_.$new();
          $scope.$parent = {
              dummyFn: function() {}
          };
          createCtrl = function createCtrl() {
              return $controller('MyController', {
                  '$q': _$q_,
                  '$scope': $scope
              });
          };
      }));
  }));
  describe("Controller stability", function() {
      it("should initialise the controller without error", function() {
          var controller = createCtrl();
      });
  });
  </code></pre>
  
  <p>As you can see the above test doesn't do anything but catch error's in creating the controller.</p>
  
  <p>Here is a mock up of the code in the controller:</p>
  
  <p><strong>Code</strong>
  </p>
  
  <pre><code>(function() {
      "use strict";
       const {angular} = window;
       angular.module('myModule', [])
       .controller('MyController', MyController);
       MyController.$inject = ['$routeParams', '$scope'];
       function MyController($routeParams, $scope) {
           var vm = this;
           $scope.$on('event-name', function(event, eventData) {
               vm.eventData = eventData;
               updateData();
           })
       }
  })();
  </code></pre>
  
  <p>The error's I get depend on how I run karma, but are loosely related it seems.</p>
  
  <p>If I run it form the command line with a <code>gulp</code> task, I get that:</p>
  
  <pre><code>TypeError: undefined is not an object (evaluating 'current.$$listenerCount[name]') in dist/app/vendor.js
  $on@dist/app/vendor&lt;line number&gt;
  </code></pre>
  
  <p>And the stack trace through angular and back to the test.</p>
  
  <p>If I run it in Karma's debug window:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'event-name' of undefined
  at Scope.$get.Scope.$on (hostname.com:9876/base/dist/vendor.js:&lt;line number&gt;)
  </code></pre>
  
  <p>And then down again though the stack trace.</p>
  
  <p>Looking at the code for <a href="https://github.com/angular/angular.js/blob/c2b8fab0a480204374d561d6b9b3d47347ac5570/src/ng/rootScope.js#L1164" rel="nofollow noreferrer"><code>$on</code></a> I can't see why it would fail in those two different ways.</p>
  
  <p>Changing the controller code to use <code>$rootScope.$on</code> seems to mollify the tests, but I don't understand why the tests require that, and not the main app.</p>
  
  <p>Why is <code>$on</code> not on <code>$scope</code> in the test, when it is in the main app?</p>