aboutsummaryrefslogtreecommitdiffstats
path: root/test/directivesSpec.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/directivesSpec.js')
-rw-r--r--test/directivesSpec.js41
1 files changed, 40 insertions, 1 deletions
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 713147ad..a640fc50 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -177,7 +177,7 @@ describe("directive", function(){
describe('ng:class', function() {
- it('should add new and remove old classes dynamically', function() {
+ it('should change current class or remove old classes dynamically', function() {
var scope = compile('<div class="existing" ng:class="dynClass"></div>');
scope.dynClass = 'A';
scope.$eval();
@@ -204,6 +204,45 @@ describe("directive", function(){
expect(element.hasClass('A')).toBeTruthy();
expect(element.hasClass('B')).toBeTruthy();
});
+
+ it('should preserve class added post compilation', function() {
+ var scope = compile('<div class="existing" ng:class="dynClass"></div>');
+ scope.dynClass = 'A';
+ scope.$eval();
+ expect(element.hasClass('existing')).toBe(true);
+
+ // add extra class, change model and eval
+ element.addClass('newClass');
+ scope.dynClass = 'B';
+ scope.$eval();
+
+ expect(element.hasClass('existing')).toBe(true);
+ expect(element.hasClass('B')).toBe(true);
+ expect(element.hasClass('newClass')).toBe(true);
+ });
+
+ it('should preserve class added post compilation even without existing classes"', function() {
+ var scope = compile('<div ng:class="dynClass"></div>');
+ scope.dynClass = 'A';
+ scope.$eval();
+ expect(element.hasClass('A')).toBe(true);
+
+ // add extra class, change model and eval
+ element.addClass('newClass');
+ scope.dynClass = 'B';
+ scope.$eval();
+
+ expect(element.hasClass('B')).toBe(true);
+ expect(element.hasClass('newClass')).toBe(true);
+ });
+
+ it('should preserve right classes"', function() {
+ var scope = compile('<div class="ui-panel ui-selected" ng:class="dynCls"></div>');
+ scope.dynCls = 'panel';
+ scope.dynCls = 'foo';
+ scope.$eval();
+ expect(element.attr('class')).toBe('ui-panel ui-selected ng-directive foo');
+ });
});