diff options
author | Wout <wout@impinc.co.uk> | 2014-06-10 13:39:15 +0200 |
---|---|---|
committer | Wout <wout@impinc.co.uk> | 2014-06-10 13:39:15 +0200 |
commit | 7e6b5edfdd08dd28120442a2c3528c3d94c346c3 (patch) | |
tree | 6693bb631dab6a126fdc214d537856c4ae9ac8f7 /spec | |
parent | 8e44d115af4907276cb23567dc2d2a10d0efdf2f (diff) | |
parent | c13717a8d8d85e5d1d408e27a6db881fe773cc04 (diff) | |
download | svg.js-1.0.0-rc.7.tar.gz svg.js-1.0.0-rc.7.zip |
Merge pull request #200 from pklingem/master1.0.0-rc.7
add class manipulation functions to Element
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/spec/element.js | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/spec/spec/element.js b/spec/spec/element.js index 919df93..064c1e8 100755 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -315,9 +315,86 @@ describe('Element', function() { expect(element).toBe(circle) }) }) - -}) + describe('classes()', function() { + it('returns an array of classes on the node', function() { + var element = draw.rect(100,100) + element.node.setAttribute('class', 'one two') + expect(element.classes()).toEqual(['one', 'two']) + }) + }) + + describe('hasClass()', function() { + it('returns true if the node has the class', function() { + var element = draw.rect(100,100) + element.node.setAttribute('class', 'one') + expect(element.hasClass('one')).toBeTruthy() + }) + + it('returns false if the node does not have the class', function() { + var element = draw.rect(100,100) + element.node.setAttribute('class', 'one') + expect(element.hasClass('two')).toBeFalsy() + }) + }) + + describe('addClass()', function() { + it('adds the class to the node', function() { + var element = draw.rect(100,100) + element.addClass('one') + expect(element.hasClass('one')).toBeTruthy() + }) + + it('does not add duplicate classes', function() { + var element = draw.rect(100,100) + element.addClass('one') + element.addClass('one') + expect(element.node.getAttribute('class')).toEqual('one') + }) + + it('returns the svg instance', function() { + var element = draw.rect(100,100) + expect(element.addClass('one')).toEqual(element) + }) + }) + + describe('removeClass()', function() { + it('removes the class from the node when the class exists', function() { + var element = draw.rect(100,100) + element.addClass('one') + element.removeClass('one') + expect(element.hasClass('one')).toBeFalsy() + }) + + it('does nothing when the class does not exist', function() { + var element = draw.rect(100,100) + element.removeClass('one') + expect(element.hasClass('one')).toBeFalsy() + }) + + it('returns the element', function() { + var element = draw.rect(100,100) + expect(element.removeClass('one')).toEqual(element) + }) + }) + describe('toggleClass()', function() { + it('adds the class when it does not already exist', function(){ + var element = draw.rect(100,100) + element.toggleClass('one') + expect(element.hasClass('one')).toBeTruthy() + }) + it('removes the class when it already exists', function(){ + var element = draw.rect(100,100) + element.addClass('one') + element.toggleClass('one') + expect(element.hasClass('one')).toBeFalsy() + }) + it('returns the svg instance', function() { + var element = draw.rect(100,100) + expect(element.toggleClass('one')).toEqual(element) + }) + }) +}) |