From 6de684c441701b88b03dee53f1baffea331fa0bf Mon Sep 17 00:00:00 2001 From: David Schnurr Date: Tue, 19 Apr 2016 17:37:47 -0400 Subject: [PATCH] Fix issue with callback executing after destroy --- src/vivus.js | 1 + test/unit/vivus.spec.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/vivus.js b/src/vivus.js index 61c708c..e0d2590 100755 --- a/src/vivus.js +++ b/src/vivus.js @@ -570,6 +570,7 @@ Vivus.prototype.stop = function () { * */ Vivus.prototype.destroy = function () { + this.stop(); var i, path; for (i = 0; i < this.map.length; i++) { path = this.map[i]; diff --git a/test/unit/vivus.spec.js b/test/unit/vivus.spec.js index 7b524b5..afd02f9 100644 --- a/test/unit/vivus.spec.js +++ b/test/unit/vivus.spec.js @@ -402,6 +402,22 @@ describe('Vivus', function () { myVivus.play(); }); + it('should stop animation if destroy has been called', function (done) { + var callbackSpy = jasmine.createSpy('spy'); + myVivus = new Vivus(svgTag, { + type: 'oneByOne', + duration: 2, + start: 'autostart' + }, callbackSpy); + + myVivus.destroy(); + + setTimeout(function () { + expect(callbackSpy.calls.count()).toEqual(0); + done(); + }, 50); + }); + it('should stop the animation once it reaches currentFrame == 0', function (done) { myVivus = new Vivus(svgTag, { type: 'oneByOne',