diff options
| author | Max Martinsson | 2012-06-07 17:25:35 +0200 | 
|---|---|---|
| committer | Misko Hevery | 2012-09-06 16:06:21 -0700 | 
| commit | cebd015f78c5e21bd37d4bc055dbcdc21dac2ef2 (patch) | |
| tree | 59fd08d49dd0186deee8b95d7dafdfe0dbc8c372 /test/ng/directive | |
| parent | fbdab513dd48f667ad857030cf4b3481ecdd9097 (diff) | |
| download | angular.js-cebd015f78c5e21bd37d4bc055dbcdc21dac2ef2.tar.bz2 | |
fix(ngClass): works with class interpolation
Closes #1016
Diffstat (limited to 'test/ng/directive')
| -rw-r--r-- | test/ng/directive/ngClassSpec.js | 33 | 
1 files changed, 33 insertions, 0 deletions
diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index e8685b7d..fc46bf7c 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -201,4 +201,37 @@ describe('ngClass', function() {      expect(e2.hasClass('C')).toBeFalsy();      expect(e2.hasClass('D')).toBeFalsy();    })); + + +  it('should reapply ngClass when interpolated class attribute changes', inject(function($rootScope, $compile) { +    element = $compile('<div class="one {{cls}} three" ng-class="{four: four}"></div>')($rootScope); + +    $rootScope.$apply(function() { +      $rootScope.cls = "two"; +      $rootScope.four = true; +    }); +    expect(element).toHaveClass('one'); +    expect(element).toHaveClass('two'); // interpolated +    expect(element).toHaveClass('three'); +    expect(element).toHaveClass('four'); + +    $rootScope.$apply(function() { +      $rootScope.cls = "too"; +    }); +    expect(element).toHaveClass('one'); +    expect(element).toHaveClass('too'); // interpolated +    expect(element).toHaveClass('three'); +    expect(element).toHaveClass('four'); // should still be there +    expect(element.hasClass('two')).toBeFalsy(); + +    $rootScope.$apply(function() { +      $rootScope.cls = "to"; +    }); +    expect(element).toHaveClass('one'); +    expect(element).toHaveClass('to'); // interpolated +    expect(element).toHaveClass('three'); +    expect(element).toHaveClass('four'); // should still be there +    expect(element.hasClass('two')).toBeFalsy(); +    expect(element.hasClass('too')).toBeFalsy(); +  }));  });  | 
