9 describe('Fx', function(){
11 beforeEach(function(){
12 this.clock = sinon.useFakeTimers();
20 Object.each(Fx.Transitions, function(value, transition){
21 if (transition == 'extend') return;
23 it('should start a Fx and call the onComplete event with ' + transition + ' as timing function', function(){
24 var onComplete = sinon.spy(),
25 onStart = sinon.spy();
29 transition: Fx.Transitions[transition],
30 onComplete: onComplete,
34 expect(onStart.called).to.equal(false);
39 expect(onStart.called).to.equal(true);
40 expect(onComplete.called).to.equal(false);
42 this.clock.tick(1000);
43 expect(onComplete.called).to.equal(true);
47 it('should cancel a Fx', function(){
48 var onCancel = sinon.spy();
52 transition: 'sine:in:out',
57 expect(onCancel.called).to.equal(false);
60 expect(onCancel.called).to.equal(true);
63 it('should set the computed value', function(){
64 var FxLog = new Class({
66 set: function(current){
75 this.clock.tick(2000);
76 expect(fx.foo).to.equal(10);
79 it('should pause and resume', function(){
80 var FxLog = new Class({
82 set: function(current){
91 this.clock.tick(1000);
97 expect(fx.foo).to.be.greaterThan(0);
98 expect(fx.foo).to.be.lessThan(1);
100 this.clock.tick(1000);
102 expect(fx.foo).to.equal(value);
105 this.clock.tick(2000);
106 expect(fx.foo).to.equal(1);
109 it('should chain the Fx', function(){
113 onComplete: function(){
121 this.clock.tick(1000);
122 this.clock.tick(1000);
124 expect(counter).to.equal(2);
127 it('should cancel the Fx after a new Fx:start with the link = cancel option', function(){
128 var onCancel = sinon.spy();
138 this.clock.tick(1000);
139 expect(onCancel.called).to.equal(true);
142 it('should return the paused state', function(){
147 expect(fx.isPaused()).to.equal(false);
149 this.clock.tick(300);
152 expect(fx.isPaused()).to.equal(true);
155 this.clock.tick(600);
156 expect(fx.isPaused()).to.equal(false);
161 describe('Fx (thenable)', function(){
163 beforeEach(function(){
166 transition: 'sine:in:out'
170 this.onFulfilled = sinon.spy(function(){ self.expectations.apply(self, arguments); });
171 this.onRejected = sinon.spy(function(){ self.expectations.apply(self, arguments); });
173 this.fx.then(this.onFulfilled, this.onRejected);
176 it('should fulfill when completed', function(done){
177 this.fx.start(10, 20);
179 expect(this.onRejected.called).to.equal(false);
180 expect(this.onFulfilled.called).to.equal(false);
182 this.expectations = function(){
185 expect(this.onRejected.called).to.equal(false);
186 expect(this.onFulfilled.called).to.equal(true);
187 expect(this.onFulfilled.args[0][0]).to.equal(null);
195 it('should reject when cancelled', function(done){
198 expect(this.onFulfilled.called).to.equal(false);
199 expect(this.onRejected.called).to.equal(false);
203 this.expectations = function(){
206 expect(this.onFulfilled.called).to.equal(false);
207 expect(this.onRejected.called).to.equal(true);
208 expect(this.onRejected.args[0][0]).to.equal(this.fx);