diff options
| author | Di Peng | 2011-06-27 16:41:08 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-06-27 22:31:29 -0700 | 
| commit | 75bc59ee4bd4528849b2c64c9854f7dbe25b29df (patch) | |
| tree | dc6f89f3cfa67814385b9a3e66d7adced47cd4db | |
| parent | 6aee2938a71c99fdd35639725c6900347999f658 (diff) | |
| download | angular.js-75bc59ee4bd4528849b2c64c9854f7dbe25b29df.tar.bz2 | |
test:ng#class: added a better unit test for ng:class
| -rw-r--r-- | test/directivesSpec.js | 36 | 
1 files changed, 30 insertions, 6 deletions
diff --git a/test/directivesSpec.js b/test/directivesSpec.js index e5b8b607..713147ad 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -175,14 +175,38 @@ describe("directive", function(){      });    }); -  it('should ng:class', function(){ -    var scope = compile('<div class="existing" ng:class="[\'A\', \'B\']"></div>'); -    scope.$eval(); -    expect(element.hasClass('existing')).toBeTruthy(); -    expect(element.hasClass('A')).toBeTruthy(); -    expect(element.hasClass('B')).toBeTruthy(); + +  describe('ng:class', function() { +    it('should add new and remove old classes dynamically', function() { +      var scope = compile('<div class="existing" ng:class="dynClass"></div>'); +      scope.dynClass = 'A'; +      scope.$eval(); +      expect(element.hasClass('existing')).toBe(true); +      expect(element.hasClass('A')).toBe(true); + +      scope.dynClass = 'B'; +      scope.$eval(); +      expect(element.hasClass('existing')).toBe(true); +      expect(element.hasClass('A')).toBe(false); +      expect(element.hasClass('B')).toBe(true); + +      delete scope.dynClass; +      scope.$eval(); +      expect(element.hasClass('existing')).toBe(true); +      expect(element.hasClass('A')).toBe(false); +      expect(element.hasClass('B')).toBe(false); +    }); + +    it('should support adding multiple classes', function(){ +      var scope = compile('<div class="existing" ng:class="[\'A\', \'B\']"></div>'); +      scope.$eval(); +      expect(element.hasClass('existing')).toBeTruthy(); +      expect(element.hasClass('A')).toBeTruthy(); +      expect(element.hasClass('B')).toBeTruthy(); +    });    }); +    it('should ng:class odd/even', function(){      var scope = compile('<ul><li ng:repeat="i in [0,1]" class="existing" ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li><ul>');      scope.$eval();  | 
