title: How to unit test spy on $emit in a directive?
body: <p>How do I check if $emit has been called in an unit test of a directive?</p>
  
  <p>My directive is fairly simple (for the purpose of illustration):</p>
  
  <pre><code>angular.module('plunker', [])
  .directive('uiList', [function () { 
      return {
          scope: {
              lengthModel: '=uiList',
          },
          link: function (scope, elm, attrs) {
              scope.$watch('lengthModel', function (newVal) {
                          scope.$emit('yolo');
              });
          }
      }
  }])
  </code></pre>
  
  <p>so every time the attribute uiList changes, it will emit the event.</p>
  
  <p>And I have unit test code as follows:</p>
  
  <pre><code>describe('Testing $emit in directive', function() {
    var scope;
    var element;
  
  
    //you need to indicate your module in a test
      beforeEach(function () {
          module('plunker');
          inject(function ($rootScope, $compile) {
              scope = $rootScope.$new();
              scope.row= 1;
              spyOn(scope,'$emit');
          element = angular.element('&lt;ul id="rows" ui-list="row"&gt;');
          $compile(element)(scope);
          });
      });
  
    it('should emit', function() {
  
      scope.$digest();
      scope.row = 2;
      scope.$digest();
      expect(scope.$emit).toHaveBeenCalledWith("yolo");
    });
  });
  </code></pre>
  
  <p>This would always give me error stating that the scope.$emit has never been called. 
  Is there something wrong with the scope? Can someone please help?</p>
  
  <p>Plunker:<a href="http://plnkr.co/edit/AqhPwp?p=preview" rel="nofollow">http://plnkr.co/edit/AqhPwp?p=preview</a></p>