summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-03-05 09:52:39 +0100
committerGitHub <noreply@github.com>2018-03-05 09:52:39 +0100
commit55874e6dd16cb85181e879b8c35b4e65bb310e11 (patch)
treefade9fb53991736c908fe3be06d03bfdb6b1b6d5
parent31e94c28d85f676a0f4ec073a06435bc86b1dc73 (diff)
parent14585d5e4f8ce51829f4da6759c2fe04dde37b5c (diff)
downloadsvg.js-55874e6dd16cb85181e879b8c35b4e65bb310e11.tar.gz
svg.js-55874e6dd16cb85181e879b8c35b4e65bb310e11.zip
Merge pull request #828 from svgdotjs/797-throw-error-in-at
make `at()` method of morphable objects throw when no destination is set (#797)
-rw-r--r--spec/spec/array.js13
-rw-r--r--spec/spec/boxes.js4
-rw-r--r--spec/spec/color.js4
-rw-r--r--spec/spec/matrix.js4
-rw-r--r--spec/spec/number.js4
-rw-r--r--spec/spec/point.js4
-rw-r--r--src/array.js2
-rw-r--r--src/boxes.js2
-rw-r--r--src/color.js2
-rw-r--r--src/matrix.js2
-rw-r--r--src/number.js2
-rw-r--r--src/patharray.js2
-rw-r--r--src/point.js2
-rw-r--r--src/pointarray.js2
14 files changed, 24 insertions, 25 deletions
diff --git a/spec/spec/array.js b/spec/spec/array.js
index 7530ea1..03046ca 100644
--- a/spec/spec/array.js
+++ b/spec/spec/array.js
@@ -113,8 +113,8 @@ describe('Array', function () {
arr1.morph(arr2)
expect(arr1.at(0.5).value).toEqual([1.5, 2.5, 3.5, 4.5])
})
- it('returns itself if no destination was specified', function() {
- expect(arr1.at(0.5)).toBe(arr1)
+ it('throws when no destination was specified', function() {
+ expect(arr1.at).toThrow()
})
})
})
@@ -221,8 +221,8 @@ describe('PointArray', function () {
arr1.morph(arr2)
expect(arr1.at(0.5).value).toEqual([[1.5, 2.5], [3.5, 4.5]])
})
- it('returns itself if no destination was specified', function() {
- expect(arr1.at(0.5)).toBe(arr1)
+ it('throws when no destination was specified', function() {
+ expect(arr1.at).toThrow()
})
})
})
@@ -394,10 +394,9 @@ describe('PathArray', function () {
expect(morphedPathArray.value[1][4]).toBe(1)
expect(morphedPathArray.value[1][5]).toBe(0)
})
- it('return itself if the destination attribute is null', function(){
+ it('throws when no destination was specified', function(){
var pathArray = new SVG.PathArray('M 13 13 A 25 37 0 0 1 43 25')
- pathArray.destination = null
- expect(pathArray.at(0.45)).toBe(pathArray)
+ expect(pathArray.at).toThrow()
})
})
diff --git a/spec/spec/boxes.js b/spec/spec/boxes.js
index 9e33c60..cc428e4 100644
--- a/spec/spec/boxes.js
+++ b/spec/spec/boxes.js
@@ -148,9 +148,9 @@ describe('Box', function() {
expect(box2.toString()).toBe('50 -100 300 300')
expect(box3.toString()).toBe('30 0 250 300')
})
- it('returns itself when no destination given', function() {
+ it('throws itself when no destination was specified', function() {
var box = new SVG.Box(10, 100, 200, 300)
- expect(box.at(0.5)).toBe(box)
+ expect(box.at).toThrow()
})
})
})
diff --git a/spec/spec/color.js b/spec/spec/color.js
index 1e86544..b70af1b 100644
--- a/spec/spec/color.js
+++ b/spec/spec/color.js
@@ -77,8 +77,8 @@ describe('Color', function() {
expect(morphed.b).toBe(255)
})
- it('returns itself when no destination specified', function() {
- expect(color.at(0.5)).toBe(color)
+ it('throws when no destination specified', function() {
+ expect(color.at).toThrow()
})
})
diff --git a/spec/spec/matrix.js b/spec/spec/matrix.js
index 0816f66..aaebd68 100644
--- a/spec/spec/matrix.js
+++ b/spec/spec/matrix.js
@@ -193,9 +193,9 @@ describe('Matrix', function() {
expect(matrix2.toString()).toBe('matrix(1,0,0,1,4,3)')
expect(matrix3.toString()).toBe('matrix(1.5,0,0,3,2,1.5)')
})
- it('returns itself when no destination specified', function() {
+ it('throws when no destination specified', function() {
var matrix = new SVG.Matrix(2, 0, 0, 5, 0, 0)
- expect(matrix.at(0.5)).toBe(matrix)
+ expect(matrix.at).toThrow()
})
})
diff --git a/spec/spec/number.js b/spec/spec/number.js
index 58c14bd..2d33fef 100644
--- a/spec/spec/number.js
+++ b/spec/spec/number.js
@@ -237,8 +237,8 @@ describe('Number', function() {
it('use the unit of this number as the unit of the returned number when the destination number as no unit', function() {
expect(expect(new SVG.Number('100s').morph(50).at(0.5).unit).toBe('s'))
})
- it('returns itself when no destination specified', function() {
- expect(number.at(0.5)).toBe(number)
+ it('throws when no destination specified', function() {
+ expect(number.at).toThrow()
})
})
diff --git a/spec/spec/point.js b/spec/spec/point.js
index 8eacb84..80cc414 100644
--- a/spec/spec/point.js
+++ b/spec/spec/point.js
@@ -117,9 +117,9 @@ describe('Point', function() {
expect(point3).toEqual(new SVG.Point(1.5, 1.5))
})
- it('returns itself when no destination specified', function() {
+ it('throws when no destination specified', function() {
var point = new SVG.Point(1,1)
- expect(point.at(0.4)).toBe(point)
+ expect(point.at).toThrow()
})
})
diff --git a/src/array.js b/src/array.js
index ca51d8e..5ce0160 100644
--- a/src/array.js
+++ b/src/array.js
@@ -49,7 +49,7 @@ SVG.extend(SVG.Array, {
// Get morphed array at given position
at: function (pos) {
// make sure a destination is defined
- if (!this.destination) return this
+ if (!this.destination) throw new Error('No destination set')
// generate morphed array
for (var i = 0, il = this.value.length, array = []; i < il; i++) {
diff --git a/src/boxes.js b/src/boxes.js
index f0154bd..de96081 100644
--- a/src/boxes.js
+++ b/src/boxes.js
@@ -74,7 +74,7 @@ SVG.Box = SVG.invent({
},
at: function (pos) {
- if (!this.destination) return this
+ if (!this.destination) throw new Error('No destination set')
return new SVG.Box(
this.x + (this.destination.x - this.x) * pos
diff --git a/src/color.js b/src/color.js
index 8f47f70..22b8506 100644
--- a/src/color.js
+++ b/src/color.js
@@ -68,7 +68,7 @@ SVG.extend(SVG.Color, {
// Get morphed color at given position
at: function (pos) {
// make sure a destination is defined
- if (!this.destination) return this
+ if (!this.destination) throw new Error('No destination set')
// normalise pos
pos = pos < 0 ? 0 : pos > 1 ? 1 : pos
diff --git a/src/matrix.js b/src/matrix.js
index e823a81..8028b15 100644
--- a/src/matrix.js
+++ b/src/matrix.js
@@ -68,7 +68,7 @@ SVG.Matrix = SVG.invent({
// Get morphed matrix at a given position
at: function (pos) {
// make sure a destination is defined
- if (!this.destination) return this
+ if (!this.destination) throw new Error('No destination set')
// calculate morphed matrix at a given position
var matrix = new SVG.Matrix({
diff --git a/src/number.js b/src/number.js
index 6413f94..ba95151 100644
--- a/src/number.js
+++ b/src/number.js
@@ -91,7 +91,7 @@ SVG.Number = SVG.invent({
// Get morphed number at given position
at: function (pos) {
// Make sure a destination is defined
- if (!this.destination) return this
+ if (!this.destination) throw new Error('No destination set')
// Generate new morphed number
return new SVG.Number(this.destination)
diff --git a/src/patharray.js b/src/patharray.js
index d9ffecd..ca58513 100644
--- a/src/patharray.js
+++ b/src/patharray.js
@@ -195,7 +195,7 @@ SVG.extend(SVG.PathArray, {
// Get morphed path array at given position
at: function (pos) {
// make sure a destination is defined
- if (!this.destination) return this
+ if (!this.destination) throw new Error('No destination set')
var sourceArray = this.value
var destinationArray = this.destination.value
diff --git a/src/point.js b/src/point.js
index 682092e..72a9572 100644
--- a/src/point.js
+++ b/src/point.js
@@ -32,7 +32,7 @@ SVG.Point = SVG.invent({
// Get morphed point at a given position
at: function (pos) {
// make sure a destination is defined
- if (!this.destination) return this
+ if (!this.destination) throw new Error('No destination set')
// calculate morphed matrix at a given position
var point = new SVG.Point({
diff --git a/src/pointarray.js b/src/pointarray.js
index ecf5c40..6229e2e 100644
--- a/src/pointarray.js
+++ b/src/pointarray.js
@@ -32,7 +32,7 @@ SVG.extend(SVG.PointArray, {
// Get morphed array at given position
at: function (pos) {
// make sure a destination is defined
- if (!this.destination) return this
+ if (!this.destination) throw new Error('No destination set')
// generate morphed point string
for (var i = 0, il = this.value.length, array = []; i < il; i++) {