avoids race condition

This commit is contained in:
Francisco Dans 2015-08-04 20:40:24 +02:00
parent 388ef63f4d
commit f9bf4264b3

View File

@ -2,15 +2,8 @@ var torque = require('../lib/torque');
var sinon = require('sinon');
require('phantomjs-polyfill');
var animator;
QUnit.module('animator', {
beforeEach: function() {
animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
}
});
asyncTest('time moves', function(assert) {
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
animator.start();
setTimeout(function(){
assert.notEqual(animator._time, 0);
@ -20,6 +13,7 @@ asyncTest('time moves', 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.rescale();
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){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
animator.pause();
animator.rescale();
assert.notOk(animator.running);
});
asyncTest("onStart runs properly", function(assert){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
animator.options.onStart = function(){
assert.ok(true);
animator.pause();
@ -42,11 +38,13 @@ asyncTest("onStart runs properly", 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()
assert.equal(animator._time, 0);
});
test("stop should call onStop", function(assert){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
animator.options.onStop = function(){
assert.ok(true);
animator.pause();
@ -55,12 +53,14 @@ test("stop should call onStop", function(assert){
});
test("altering steps should rescale", function(assert){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
sinon.spy(animator, "rescale");
animator.steps(600);
assert.ok(animator.rescale.calledOnce);
});
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();
setTimeout(function(){
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){
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
var done = assert.async();
animator.options.loop = false;
animator.toggle();