From f9bf4264b3fe13352699572711d1ed4fcc78c641 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Tue, 4 Aug 2015 20:40:24 +0200 Subject: [PATCH] avoids race condition --- test/animator.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/animator.js b/test/animator.js index 5b702a2..4165754 100644 --- a/test/animator.js +++ b/test/animator.js @@ -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();