Skip to content

Commit

Permalink
fix(pauseResume): Fix a script error on stop() (#276)
Browse files Browse the repository at this point in the history
* fix(pauseResume): Fix a script error on stop()

When you call it on elements which is not animated,
script error occurs because __aniProp is not exist.

Close #276
  • Loading branch information
jongmoon authored Jul 6, 2016
1 parent 675ba33 commit 5895db1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/hook/pauseResume.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ eg.module("pauseResume", ["jQuery"], function($) {
return this.each(function() {
var p;

// When this element was not animated properly, do nothing.
if (getStatus(this) === "empty") {
return;
}

if (!clearQ) {
p = this.__aniProps.shift();
p && p.clearEasingFn();
Expand Down
47 changes: 47 additions & 0 deletions test/unit/js/pauseResume.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,44 @@ QUnit.config.reorder = false;
var hooks = {
beforeEach: function() {
this.$el = $("#box1");
delete this.$el[0].__aniProps;
},
afterEach: function() {
this.$el.css({"left": 0});
}
};

module("Initialization", hooks);

test("stop on non-animated element", function(assert) {
// Given
// When
this.$el.stop();

// Then
ok(true, "stop() is called successfully without script errors.");
});

test("stop on animated element", function(assert) {
var done = assert.async();
var duration = 3000;
var stopTime = 500;

// Given
this.$el
.animate({"left": "100px"}, duration)

// When
setTimeout($.proxy(function() {
// Call stop
this.$el.stop();

//Then
ok(true, "stop called successfully");
done();
}, this), stopTime);
});

test("pause", function(assert) {
var done = assert.async();

Expand Down Expand Up @@ -265,3 +296,19 @@ test("Delay pause/resume test", function(assert) {
done();
}, this), totalDuration + totalDuration * 0.2);
});

test("delay on non-animated element test", function(assert) {
var done = assert.async();
var t1 = new Date().getTime();
// Given
// When
this.$el.delay(1000).queue(function(next) {
var t2 = new Date().getTime();
// Then
ok((t2-t1) >= 1000, "delay() successfully");
done();

//MUST call next() to dequeue the next item. otherwise next item will not be dequeue automatically.
next();
});
});

0 comments on commit 5895db1

Please sign in to comment.