diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-26 09:27:36 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-26 09:27:36 +1000 |
commit | 4f6e1fb5e66960040836fa38720933ee553c1d0f (patch) | |
tree | f4e79a37752b5cf7fded8b98887006e4f0925e93 /spec | |
parent | ed08a24bbbc2774e1a570430c0243db4f51883f3 (diff) | |
download | svg.js-4f6e1fb5e66960040836fa38720933ee553c1d0f.tar.gz svg.js-4f6e1fb5e66960040836fa38720933ee553c1d0f.zip |
added tests for class.js
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/modules/optional/class.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/spec/spec/modules/optional/class.js b/spec/spec/modules/optional/class.js new file mode 100644 index 0000000..b6bb42b --- /dev/null +++ b/spec/spec/modules/optional/class.js @@ -0,0 +1,82 @@ +/* globals describe, expect, it */ + +import { Rect } from '../../../../src/main.js' + +describe('class.js', () => { + describe('Dom', () => { + describe('classes()', () => { + it('returns all classes on an element', () => { + const rect = new Rect({ class: 'myClass myClass2' }) + expect(rect.classes()).toEqual([ 'myClass', 'myClass2' ]) + }) + + it('returns an empty array if no class on the element', () => { + const rect = new Rect() + expect(rect.classes()).toEqual([]) + }) + }) + + describe('hasClass()', () => { + it('returns true if a class is present on the element', () => { + const rect = new Rect({ class: 'myClass myClass2' }) + expect(rect.hasClass('myClass')).toBe(true) + }) + + it('returns false if a class is not present on the element', () => { + const rect = new Rect({ class: 'myClass myClass2' }) + expect(rect.hasClass('myClass3')).toBe(false) + }) + }) + + describe('addClass()', () => { + it('returns itself', () => { + const rect = new Rect({ class: 'myClass myClass2' }) + expect(rect.addClass('myClass3')).toBe(rect) + }) + + it('adds a class to the element', () => { + const rect = new Rect({ class: 'myClass myClass2' }).addClass('myClass3') + expect(rect.classes()).toEqual([ 'myClass', 'myClass2', 'myClass3' ]) + }) + + it('does nothing if class already present on the element', () => { + const rect = new Rect({ class: 'myClass myClass2' }).addClass('myClass') + expect(rect.classes()).toEqual([ 'myClass', 'myClass2' ]) + }) + }) + + describe('removeClass()', () => { + it('returns itself', () => { + const rect = new Rect({ class: 'myClass myClass2' }) + expect(rect.removeClass('myClass3')).toBe(rect) + }) + + it('removes a class from the element', () => { + const rect = new Rect({ class: 'myClass myClass2' }).removeClass('myClass2') + expect(rect.classes()).toEqual([ 'myClass' ]) + }) + + it('does nothing if class is not present on the element', () => { + const rect = new Rect({ class: 'myClass myClass2' }).removeClass('myClass3') + expect(rect.classes()).toEqual([ 'myClass', 'myClass2' ]) + }) + }) + + describe('toggleClass()', () => { + it('returns itself', () => { + const rect = new Rect({ class: 'myClass myClass2' }) + expect(rect.toggleClass('myClass3')).toBe(rect) + }) + + it('removes a class from the element when its present', () => { + const rect = new Rect({ class: 'myClass myClass2' }).toggleClass('myClass2') + expect(rect.classes()).toEqual([ 'myClass' ]) + }) + + it('adds a class to the element if its not present', () => { + const rect = new Rect({ class: 'myClass myClass2' }).toggleClass('myClass3') + expect(rect.classes()).toEqual([ 'myClass', 'myClass2', 'myClass3' ]) + }) + }) + }) +}) |