title: Change in one-way bound directive attribute during test not updating directive scope
body: <p>I'm currently attempting to test an angular directive using jasmine.</p>
  
  <p>Here is a simplified example of what the directive under test looks like:</p>
  
  <pre><code>angular.module('app', []).directive('testDirective', [
    function() {
      return {
        restrict:'A',
        scope: {
          myAttr: '@'
        },
        link: function(scope, element, attrs) {
          element.html(scope.myAttr);
  
          scope.$watch('myAttr', function(n, o) {
            if(n !== o) {
              element.html(n);
            }
          });
        }
      };
    }
  ]);
  </code></pre>
  
  <p>Using an isolate scope, it is one-way binding the value of the attribute data-my-attr to the scope value of myAttr and then watching the value of myAttr for any change, at which time it updates the displayed element.</p>
  
  <p>Once again, this code has been heavily modified for clarity, so forgive the highly contrived example.</p>
  
  <p>The test is compiling an element containing this directive, verifying that the initial html of the element is set correctly (it is) and then changing the value of the attribute and expecting the corresponding change in the element to occur (it is not). This is a simplified version of the test code.</p>
  
  <pre><code>it('fires myAttr watch', function() {
      var body = angular.element('body');
      var template = angular.element('&lt;div id="testid" data-test-directive data-my-attr="initialValue"/&gt;');
  
      body.append([template]);
      compile(template)(scope);
      scope.$digest();
  
      expect(angular.element('#testid').text()).toEqual('initialValue');
  
      template.attr('data-my-attr', 'newValue');
  
      scope.$digest();
  
      expect(angular.element('#testid').text()).toEqual('newValue');
    });
  </code></pre>
  
  <p>Although this directive works as expected when used in production, under test it seems that updating the value of the attribute doesn't cause the corresponding scope value to update, which results in the watch never firing. Why doesn't the value on the scope get updated, and why does this only happen in tests?</p>
  
  <p>Here is a plunkr demonstrating the problem <a href="http://plnkr.co/edit/MmS1X2zrPZyGSUIVUsDg?p=preview" rel="nofollow">http://plnkr.co/edit/MmS1X2zrPZyGSUIVUsDg?p=preview</a></p>
  
  <p>Any ideas?</p>