From 75bc59ee4bd4528849b2c64c9854f7dbe25b29df Mon Sep 17 00:00:00 2001 From: Di Peng Date: Mon, 27 Jun 2011 16:41:08 -0700 Subject: test:ng#class: added a better unit test for ng:class --- test/directivesSpec.js | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'test/directivesSpec.js') 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('
'); - 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('
'); + 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('
'); + 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('