diff options
author | wout <wout@impinc.co.uk> | 2014-03-04 22:19:01 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-03-04 22:19:01 +0100 |
commit | 1286e3de26baa3d75ec6a6eafbb2eaa11305c2e1 (patch) | |
tree | b39257a6256836b9e645f5e5faf37adcbe8d4c4d /spec | |
parent | f3b9e808601e8aa250b9373447527ca67ba75ec4 (diff) | |
download | svg.js-1286e3de26baa3d75ec6a6eafbb2eaa11305c2e1.tar.gz svg.js-1286e3de26baa3d75ec6a6eafbb2eaa11305c2e1.zip |
Bumped to 1.0.0-rc.6
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/spec/array.js | 20 | ||||
-rwxr-xr-x | spec/spec/element.js | 9 | ||||
-rwxr-xr-x | spec/spec/text.js | 28 |
3 files changed, 32 insertions, 25 deletions
diff --git a/spec/spec/array.js b/spec/spec/array.js index c051976..05ea837 100755 --- a/spec/spec/array.js +++ b/spec/spec/array.js @@ -1,36 +1,42 @@ describe('Array', function () { + var array it('parses a matrix array correctly to string', function() { - var array = new SVG.Array([ .343, .669, .119, 0, 0 + array = new SVG.Array([ .343, .669, .119, 0, 0 , .249, -.626, .130, 0, 0 , .172, .334, .111, 0, 0 , .000, .000, .000, 1, -0 ]) expect(array + '').toBe('0.343 0.669 0.119 0 0 0.249 -0.626 0.13 0 0 0.172 0.334 0.111 0 0 0 0 0 1 0') }) - + describe('reverse()', function() { + it('reverses the array', function() { + array = new SVG.Array([1 ,2 ,3, 4, 5]).reverse() + expect(array.value).toEqual([5, 4, 3, 2, 1]) + }) + it('returns itself', function() { + array = new SVG.Array() + expect(array.reverse()).toBe(array) + }) + }) }) describe('PointArray', function () { - it('parses a string to a point array', function() { var array = new SVG.PointArray('0,1 -.05,7.95 1000.0001,-200.222') expect(array.valueOf()).toEqual([[0, 1], [-0.05, 7.95], [1000.0001, -200.222]]) }) - it('parses a points array correctly to string', function() { var array = new SVG.PointArray([[0,.15], [-100,-3.141592654], [50,100]]) expect(array + '').toBe('0,0.15 -100,-3.141592654 50,100') }) - }) -/* toUpperCase() for Firefox */ describe('PathArray', function () { - var p1, p2 + var p1, p2, p3 beforeEach(function() { p1 = new SVG.PathArray('m10 10 h 80 v 80 h -80 l 300 400 z') diff --git a/spec/spec/element.js b/spec/spec/element.js index 22b09bf..919df93 100755 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -57,15 +57,16 @@ describe('Element', function() { }) it('gets the "style" attribute as a string', function() { rect.style('cursor', 'pointer') - expect(stripped(rect.attr('style'))).toBe('cursor:pointer;') + expect(rect.node.style.cursor).toBe('pointer') }) it('redirects to the style() method when setting a style string', function() { rect.attr('style', 'cursor:move;') - expect(stripped(rect.node.getAttribute('style'))).toBe('cursor:move;') + expect(rect.node.style.cursor).toBe('move') }) it('should remove style attribute on node if the style is empty', function() { - rect.style('style', '') - expect(rect.node.getAttribute('style')).toBe(null) + rect.style('cursor', 'move') + rect.style('cursor', '') + expect(rect.style.cursor).toBe(undefined) }) it('should act as a global getter when no arguments are given', function() { rect.fill('#ff0066') diff --git a/spec/spec/text.js b/spec/spec/text.js index f9019a2..6c4d9c6 100755 --- a/spec/spec/text.js +++ b/spec/spec/text.js @@ -1,6 +1,6 @@ // IMPORTANT!!! -// The native getBBox() on text elements is not accurate to the pixel. -// Therefore some values are treated with the approximately() function. +// The native getBBox() on text elements isn't always accurate in the decimals. +// Therefore sometimes some rounding is used to make test work as expected. describe('Text', function() { var text @@ -15,50 +15,50 @@ describe('Text', function() { describe('x()', function() { it('returns the value of x without an argument', function() { - expect(approximately(text.x())).toBe(approximately(0)) + expect(text.x()).toBe(0) }) it('sets the value of x with the first argument', function() { text.x(123) var box = text.bbox() - expect(approximately(box.x, 5)).toBe(approximately(123, 5)) + expect(box.x).toBe(123) }) it('sets the value of x based on the anchor with the first argument', function() { text.x(123, true) var box = text.bbox() - expect(approximately(box.x, 5)).toBe(approximately(123, 5)) + expect(box.x).toBe(123) }) }) describe('y()', function() { it('returns the value of y without an argument', function() { - expect(text.y()).toBe(0) + expect(text.y(0).y()).toBe(0) }) it('sets the value of y with the first argument', function() { text.y(345) var box = text.bbox() - expect(approximately(box.y, 5)).toBe(approximately(345, 5)) + expect(box.y).toBe(345) }) it('sets the value of y based on the anchor with the first argument', function() { text.y(345, true) var box = text.bbox() - expect(approximately(box.y, 5)).toBe(approximately(345, 5)) + expect(box.y).toBe(345) }) }) describe('cx()', function() { it('returns the value of cx without an argument', function() { var box = text.bbox() - expect(approximately(text.cx())).toBe(approximately(box.width / 2)) + expect(text.cx()).toBe(box.width / 2) }) it('sets the value of cx with the first argument', function() { text.cx(123) var box = text.bbox() - expect(approximately(box.cx, 5)).toBe(approximately(123, 5)) + expect(box.cx).toBe(123) }) it('sets the value of cx based on the anchor with the first argument', function() { text.cx(123, true) var box = text.bbox() - expect(approximately(box.cx, 5)).toBe(approximately(123, 5)) + expect(box.cx).toBe(123) }) }) @@ -70,7 +70,7 @@ describe('Text', function() { it('sets the value of cy with the first argument', function() { text.cy(345) var box = text.bbox() - expect(approximately(box.cy, 5)).toBe(approximately(345, 5)) + expect(Math.round(box.cy * 10) / 10).toBe(345) }) }) @@ -87,8 +87,8 @@ describe('Text', function() { it('sets the cx and cy position', function() { text.center(321,567) var box = text.bbox() - expect(approximately(box.cx, 5)).toBe(approximately(321, 5)) - expect(approximately(box.cy, 6)).toBe(approximately(567, 6)) + expect(box.cx).toBe(321) + expect(Math.round(box.cy * 10) / 10).toBe(567) }) }) |