diff options
| author | Pete Bacon Darwin | 2013-04-16 12:29:56 +0100 |
|---|---|---|
| committer | Pete Bacon Darwin | 2013-04-16 13:15:49 +0100 |
| commit | 0ac969a5ee1687cfd4517821943f34fe948bb3fc (patch) | |
| tree | 15fe985df387c9145b39b1659976d93a60d2c27f /test/ng/directive/ngClassSpec.js | |
| parent | 465238613b5b849bf833bdc71d3b42f15dc0e19b (diff) | |
| download | angular.js-0ac969a5ee1687cfd4517821943f34fe948bb3fc.tar.bz2 | |
fix(ngClass): should remove classes when object is the same but property has changed
If you wire up ngClass directly to an object on the scope, e.g. ng-class="myClasses",
where scope.myClasses = { 'classA': true, 'classB': false },
there was a bug that changing scope.myClasses.classA = false, was not being picked
up and classA was not being removed from the element's CSS classes.
This fix uses angular.equals for the comparison and ensures that oldVal is a copy of
(rather than a reference to) the newVal.
Diffstat (limited to 'test/ng/directive/ngClassSpec.js')
| -rw-r--r-- | test/ng/directive/ngClassSpec.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index d4bd76fe..e73713d8 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -43,7 +43,7 @@ describe('ngClass', function() { 'expressions', inject(function($rootScope, $compile) { var element = $compile( '<div class="existing" ' + - 'ng-class="{A: conditionA, B: conditionB(), AnotB: conditionA&&!conditionB}">' + + 'ng-class="{A: conditionA, B: conditionB(), AnotB: conditionA&&!conditionB()}">' + '</div>')($rootScope); $rootScope.conditionA = true; $rootScope.$digest(); @@ -52,7 +52,7 @@ describe('ngClass', function() { expect(element.hasClass('B')).toBeFalsy(); expect(element.hasClass('AnotB')).toBeTruthy(); - $rootScope.conditionB = function() { return true }; + $rootScope.conditionB = function() { return true; }; $rootScope.$digest(); expect(element.hasClass('existing')).toBeTruthy(); expect(element.hasClass('A')).toBeTruthy(); @@ -61,6 +61,20 @@ describe('ngClass', function() { })); + it('should remove classes when the referenced object is the same but its property is changed', + inject(function($rootScope, $compile) { + var element = $compile('<div ng-class="classes"></div>')($rootScope); + $rootScope.classes = { A: true, B: true }; + $rootScope.$digest(); + expect(element.hasClass('A')).toBeTruthy(); + expect(element.hasClass('B')).toBeTruthy(); + $rootScope.classes.A = false; + $rootScope.$digest(); + expect(element.hasClass('A')).toBeFalsy(); + expect(element.hasClass('B')).toBeTruthy(); + })); + + it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) { element = $compile('<div class="existing" ng-class="\'A B\'"></div>')($rootScope); $rootScope.$digest(); |
