avoids race condition
This commit is contained in:
parent
388ef63f4d
commit
f9bf4264b3
@ -2,15 +2,8 @@ var torque = require('../lib/torque');
|
|||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
require('phantomjs-polyfill');
|
require('phantomjs-polyfill');
|
||||||
|
|
||||||
var animator;
|
|
||||||
|
|
||||||
QUnit.module('animator', {
|
|
||||||
beforeEach: function() {
|
|
||||||
animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
asyncTest('time moves', function(assert) {
|
asyncTest('time moves', function(assert) {
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
animator.start();
|
animator.start();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
assert.notEqual(animator._time, 0);
|
assert.notEqual(animator._time, 0);
|
||||||
@ -20,6 +13,7 @@ asyncTest('time moves', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("rescale should resume animation if previously playing", function(assert){
|
test("rescale should resume animation if previously playing", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
animator.toggle();
|
animator.toggle();
|
||||||
animator.rescale();
|
animator.rescale();
|
||||||
assert.ok(animator.running);
|
assert.ok(animator.running);
|
||||||
@ -27,12 +21,14 @@ test("rescale should resume animation if previously playing", function(assert){
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("rescale shouldn't resume animation if previously paused", function(assert){
|
test("rescale shouldn't resume animation if previously paused", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
animator.pause();
|
animator.pause();
|
||||||
animator.rescale();
|
animator.rescale();
|
||||||
assert.notOk(animator.running);
|
assert.notOk(animator.running);
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("onStart runs properly", function(assert){
|
asyncTest("onStart runs properly", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
animator.options.onStart = function(){
|
animator.options.onStart = function(){
|
||||||
assert.ok(true);
|
assert.ok(true);
|
||||||
animator.pause();
|
animator.pause();
|
||||||
@ -42,11 +38,13 @@ asyncTest("onStart runs properly", function(assert){
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("stop should take the pointer to position zero", function(assert){
|
test("stop should take the pointer to position zero", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
animator.stop()
|
animator.stop()
|
||||||
assert.equal(animator._time, 0);
|
assert.equal(animator._time, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("stop should call onStop", function(assert){
|
test("stop should call onStop", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
animator.options.onStop = function(){
|
animator.options.onStop = function(){
|
||||||
assert.ok(true);
|
assert.ok(true);
|
||||||
animator.pause();
|
animator.pause();
|
||||||
@ -55,12 +53,14 @@ test("stop should call onStop", function(assert){
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("altering steps should rescale", function(assert){
|
test("altering steps should rescale", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
sinon.spy(animator, "rescale");
|
sinon.spy(animator, "rescale");
|
||||||
animator.steps(600);
|
animator.steps(600);
|
||||||
assert.ok(animator.rescale.calledOnce);
|
assert.ok(animator.rescale.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("tick should set time to zero if steps are bigger than range", function(assert){
|
asyncTest("tick should set time to zero if steps are bigger than range", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
animator.start();
|
animator.start();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
animator._time = 0;
|
animator._time = 0;
|
||||||
@ -72,6 +72,7 @@ asyncTest("tick should set time to zero if steps are bigger than range", functio
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("tick should pause animation on end if loop is disabled", function(assert){
|
QUnit.test("tick should pause animation on end if loop is disabled", function(assert){
|
||||||
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
|
||||||
var done = assert.async();
|
var done = assert.async();
|
||||||
animator.options.loop = false;
|
animator.options.loop = false;
|
||||||
animator.toggle();
|
animator.toggle();
|
||||||
|
Loading…
Reference in New Issue
Block a user