Skip to content

Commit

Permalink
Fix issue with callback executing after destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
schnerd committed Apr 19, 2016
1 parent bb58df2 commit 6de684c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/vivus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
16 changes: 16 additions & 0 deletions test/unit/vivus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6de684c

Please sign in to comment.