diff --git a/lib/tests/2.3.3.js b/lib/tests/2.3.3.js index 2d5e135..1c1a5f9 100644 --- a/lib/tests/2.3.3.js +++ b/lib/tests/2.3.3.js @@ -14,23 +14,6 @@ var sentinel = { sentinel: "sentinel" }; // a sentinel fulfillment value to test var other = { other: "other" }; // a value we don't want to be strict equal to var sentinelArray = [sentinel]; // a sentinel fulfillment value to test when we need an array -function testPromiseResolution(xFactory, test) { - specify("via return from a fulfilled promise", function (done) { - var promise = resolved(dummy).then(function onBasePromiseFulfilled() { - return xFactory(); - }); - - test(promise, done); - }); - - specify("via return from a rejected promise", function (done) { - var promise = rejected(dummy).then(null, function onBasePromiseRejected() { - return xFactory(); - }); - - test(promise, done); - }); -} function testCallingResolvePromise(yFactory, stringRepresentation, test) { describe("`y` is " + stringRepresentation, function () { @@ -43,7 +26,21 @@ function testCallingResolvePromise(yFactory, stringRepresentation, test) { }; } - testPromiseResolution(xFactory, test); + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); + }); }); describe("`then` calls `resolvePromise` asynchronously", function () { @@ -57,7 +54,21 @@ function testCallingResolvePromise(yFactory, stringRepresentation, test) { }; } - testPromiseResolution(xFactory, test); + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); + }); }); }); } @@ -73,7 +84,21 @@ function testCallingRejectPromise(r, stringRepresentation, test) { }; } - testPromiseResolution(xFactory, test); + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); + }); }); describe("`then` calls `rejectPromise` asynchronously", function () { @@ -87,7 +112,21 @@ function testCallingRejectPromise(r, stringRepresentation, test) { }; } - testPromiseResolution(xFactory, test); + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); + }); }); }); } @@ -141,11 +180,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }); } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function () { assert.strictEqual(numberOfTimesThenWasRetrieved, 1); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -169,11 +223,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }); } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function () { assert.strictEqual(numberOfTimesThenWasRetrieved, 1); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -199,11 +268,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { return x; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function () { assert.strictEqual(numberOfTimesThenWasRetrieved, 1); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); }); @@ -222,11 +306,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { } describe("`e` is " + stringRepresentation, function () { - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, e); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); } @@ -251,10 +350,25 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { return x; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function () { done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -280,10 +394,25 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }); } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function () { done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -367,11 +496,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -388,11 +532,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -411,11 +570,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -435,11 +609,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -459,11 +648,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -477,11 +681,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -498,11 +717,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -521,11 +755,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -539,11 +788,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -560,11 +824,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -583,12 +862,12 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); - }); + } }); describe("calling `resolvePromise` with an asynchronously-fulfilled promise, then calling it again, both " + @@ -607,12 +886,12 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); - }); + } }); describe("calling `resolvePromise` with an asynchronously-rejected promise, then calling it again, both " + @@ -631,11 +910,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -649,11 +943,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -670,11 +979,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -693,11 +1017,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -718,7 +1057,7 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { savedRejectPromise = null; }); - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { var timesFulfilled = 0; var timesRejected = 0; @@ -750,7 +1089,23 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { assert.strictEqual(timesRejected, 0); done(); }, 100); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); + }); }); @@ -766,11 +1121,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -789,11 +1159,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -812,11 +1197,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -830,11 +1230,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -849,11 +1264,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -868,11 +1298,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); }); @@ -887,11 +1332,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -907,11 +1367,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); @@ -927,11 +1402,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { }; } - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(null, function (reason) { assert.strictEqual(reason, sentinel); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); }); @@ -951,11 +1441,26 @@ describe("2.3.3: Otherwise, if `x` is an object or function,", function () { } describe("`then` is " + stringRepresentation, function () { - testPromiseResolution(xFactory, function (promise, done) { + function test(promise, done) { promise.then(function (value) { assert.strictEqual(value, x); done(); }); + } + specify("via return from a fulfilled promise", function (done) { + var promise = resolved(dummy).then(function onBasePromiseFulfilled() { + return xFactory(); + }); + + test(promise, done); + }); + + specify("via return from a rejected promise", function (done) { + var promise = rejected(dummy).then(null, function onBasePromiseRejected() { + return xFactory(); + }); + + test(promise, done); }); }); }