Skip to content
This repository has been archived by the owner on Dec 8, 2019. It is now read-only.

Commit

Permalink
2.2.2 when onFulfilled is a function:
Browse files Browse the repository at this point in the history
- corrected comment on promiseHandler to match with usages
- changed calling of done to timeout after async scenario as [suggested](promises-aplus/promises-tests#52 (comment)) by domenic
  • Loading branch information
karfau committed Feb 4, 2014
1 parent 3c56724 commit 4c1c28f
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions test/promises/aplus/_2_2_then/_2_When_onFulfilled_is_a_function.as
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package promises.aplus._2_2_then {
import org.hamcrest.Matcher;
import org.hamcrest.collection.array;

import promises.aplus.*;

import flash.utils.setTimeout;

import org.flexunit.assertThat;

import org.flexunit.asserts.assertFalse;
import org.flexunit.asserts.assertTrue;
import org.hamcrest.object.strictlyEqualTo;

import promises.aplus.*;

/**
* These are the tests for the the following section of the spec:
* http://promisesaplus.com/#the__method
Expand All @@ -31,13 +27,10 @@ public class _2_When_onFulfilled_is_a_function extends BasePromiseSpec {

/**
* there are two cases in which this can end the (async) execution of the test:
* a) when the reject handler gets called after the resolved handler the test fails
* b) when the reject handler gets called first it executes the done parameter
*
* all testcases use afterTick() for a second delay in which execution of the rejected handler after the resolved handler could happen,
* before completing the execution of the test.
* a) when the resolve handler gets called with a value different from sentinel the test fails
* b) when the resolve handler gets called with value being sentinel it executes the done parameter
*
* @see com.codecatalyst.promise.spec.BasePromiseSpec.afterTick()
* all test use the timeout to fail after a certain delay when the handler is not called.
*/
protected function promiseHandler(promise:Promise, done:Function):void {
promise.then(function onFulfilled(value:*):void {
Expand Down Expand Up @@ -166,35 +159,26 @@ public class _2_When_onFulfilled_is_a_function extends BasePromiseSpec {
var d:Deferred = deferred();
var timesCalled:Array = [0,0,0];

var matcher:Matcher = array(1,1,1);
function complete():void {
if(matcher.matches(timesCalled)){
done();
}
}

d.promise.then(function onFulfilled():void {
timesCalled[0]++;
assertThat(timesCalled[0], 1);
complete();
});
setTimeout(function ():void {
d.promise.then(function onFulfilled():void {
timesCalled[1]++;
assertThat(timesCalled[1], 1);
complete();
});
}, 50);
setTimeout(function ():void {
d.promise.then(function onFulfilled():void {
timesCalled[2]++;
assertThat(timesCalled[2], 1);
complete();
});
}, 100);

setTimeout(function ():void {
d.resolve(dummy);
setTimeout(done,100);
}, 150);
}
[Test(async)]
Expand All @@ -203,27 +187,18 @@ public class _2_When_onFulfilled_is_a_function extends BasePromiseSpec {
var d:Deferred = deferred();
var timesCalled:Array = [0,0];

var matcher:Matcher = array(1,1);
function complete():void {
if(matcher.matches(timesCalled)){
done();
}
}

d.promise.then(function onFulfilled():void {
timesCalled[0]++;
assertThat(timesCalled[0], 1);
complete();
});

d.resolve(dummy);

d.promise.then(function onFulfilled():void {
timesCalled[1]++;
assertThat(timesCalled[1], 1);
complete();
});

setTimeout(done,150);
}


Expand Down

0 comments on commit 4c1c28f

Please sign in to comment.