aboutsummaryrefslogtreecommitdiffstats
path: root/test/jqLiteSpec.js
diff options
context:
space:
mode:
authorIgor Minar2011-09-01 01:57:49 -0700
committerIgor Minar2011-09-01 16:37:08 -0700
commit2a8fe56997fddbad673748ce02abf649a709c4ca (patch)
treedef88fb0f27de54d17315f75da86fe12977eece8 /test/jqLiteSpec.js
parent622c3ec97409c67ff316c317771b47880fa5c1e8 (diff)
downloadangular.js-2a8fe56997fddbad673748ce02abf649a709c4ca.tar.bz2
fix(ng:class): make ng:class friendly towards other code adding/removing classes
ng:class as well as ng:class-odd and ng:class-even always reset the class list to whatever it was before compilation, this makes it impossible to create another directive which adds its own classes on the element on which ng:class was applied. the fix simply removes all classes that were added previously by ng:class and add classes that the ng:class expression evaluates to. we can now guarantee that we won't clobber stuff added before or after compilation as long as all class names are unique. in order to implement this I had to beef up jqLite#addClass and jqLite#removeClass to be able to add/remove multiple classes without creating duplicates.
Diffstat (limited to 'test/jqLiteSpec.js')
-rw-r--r--test/jqLiteSpec.js37
1 files changed, 35 insertions, 2 deletions
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index f2a99943..673bee78 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -190,14 +190,15 @@ describe('jqLite', function(){
});
- describe('addClass', function(){
- it('should allow adding of class', function(){
+ describe('addClass', function() {
+ it('should allow adding of class', function() {
var selector = jqLite([a, b]);
expect(selector.addClass('abc')).toEqual(selector);
expect(jqLite(a).hasClass('abc')).toEqual(true);
expect(jqLite(b).hasClass('abc')).toEqual(true);
});
+
it('should ignore falsy values', function() {
var jqA = jqLite(a);
expect(jqA[0].className).toBe('');
@@ -211,6 +212,28 @@ describe('jqLite', function(){
jqA.addClass(false);
expect(jqA[0].className).toBe('');
});
+
+
+ it('should allow multiple classes to be added in a single string', function() {
+ var jqA = jqLite(a);
+ expect(a.className).toBe('');
+
+ jqA.addClass('foo bar baz');
+ expect(a.className).toBe('foo bar baz');
+ });
+
+
+ it('should not add duplicate classes', function() {
+ var jqA = jqLite(a);
+ expect(a.className).toBe('');
+
+ a.className = 'foo';
+ jqA.addClass('foo');
+ expect(a.className).toBe('foo');
+
+ jqA.addClass('bar foo baz');
+ expect(a.className).toBe('foo bar baz');
+ });
});
@@ -246,6 +269,7 @@ describe('jqLite', function(){
expect(jqLite(b).hasClass('abc')).toEqual(false);
});
+
it('should correctly remove middle class', function() {
var element = jqLite('<div class="foo bar baz"></div>');
expect(element.hasClass('bar')).toBe(true);
@@ -256,6 +280,15 @@ describe('jqLite', function(){
expect(element.hasClass('bar')).toBe(false);
expect(element.hasClass('baz')).toBe(true);
});
+
+
+ it('should remove multiple classes specified as one string', function() {
+ var jqA = jqLite(a);
+
+ a.className = 'foo bar baz';
+ jqA.removeClass('foo baz noexistent');
+ expect(a.className).toBe('bar');
+ });
});
});