title: Unit test angular directive that uses ngModel
body: <p>I am trying to unit test a directive that uses ngModel and having difficulties.  It seems that  the link function of my directive is never being called...</p>
  
  <p>Here is my directive code:</p>
  
  <pre><code>coreModule.directive('coreUnit', ['$timeout', function ($timeout) {
      return {
          restrict: 'E',
          require: '?ngModel',
          template: "{{output}}",
          link: function (scope, elem, attrs, ngModelCtrl) {
              ngModelCtrl.$render = function () {
                  render(ngModelCtrl.$modelValue);
              };
              console.log("called");
              function render(unit) {
                  if (unit) {
                      var output = '(' +
                          unit.numerator +
                          (unit.denominator == '' ? '' : '/') +
                          unit.denominator +
                          (unit.rate == 'NONE' || unit.rate == '' ? '' : '/' + unit.rate) +
                          ')';
                      scope.output = output == '()' ? '' : output;
                  }
              }
          }
      }
  }]);
  </code></pre>
  
  <p>Here is my test spec:</p>
  
  <pre><code>describe('core', function () {
      describe('coreUnitDirective', function () {
          beforeEach(module('core'));
  
          var scope,
              elem;
  
          var tpl = '&lt;core-unit ng-model="myUnit"&gt;&lt;/core-unit&gt;';
  
          beforeEach(inject(function ($rootScope, $compile) {
              scope = $rootScope.$new();
              scope.myUnit = {};
              elem = $compile(tpl)(scope);
              scope.$digest();
          }));
  
          it('the unit should be empty', function () {
              expect(elem.html()).toBe('');
          });
  
          it('should show (boe)', function () {
              scope.myUnit = {
                  numerator: 'boe',
                  denominator: "",
                  rate: ""
              };
              scope.$digest();
              expect(elem.html()).toContain('(boe)');
          });
      });
  });
  </code></pre>
  
  <p>The console log output "called" is never occurring and obviously the elem in my test spec is never updating.</p>
  
  <p>What am I doing wrong??</p>