mock-promises
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -28,2 +28,5 @@ (function (root, factory) { | ||
var getValue = function(promise) { | ||
if(promise._returnedMockPromise) { | ||
return getValue(promise._returnedMockPromise); | ||
} | ||
if(isFunction(promise.inspect)) { | ||
@@ -44,2 +47,5 @@ //Q, mockedNative | ||
var getReason = function(promise) { | ||
if(promise._returnedMockPromise) { | ||
return getReason(promise._returnedMockPromise); | ||
} | ||
if(isFunction(promise.inspect)) { | ||
@@ -60,2 +66,5 @@ //Q, mockedNative | ||
var isFulfilled = function(promise) { | ||
if(promise._returnedMockPromise) { | ||
return isFulfilled(promise._returnedMockPromise); | ||
} | ||
if(isFunction(promise.isFulfilled)) { | ||
@@ -73,2 +82,5 @@ //Q, mockedNative, bluebird | ||
var isRejected = function(promise) { | ||
if(promise._returnedMockPromise) { | ||
return isRejected(promise._returnedMockPromise); | ||
} | ||
if(isFunction(promise.isRejected)) { | ||
@@ -103,3 +115,3 @@ //Q, mockedNative | ||
} | ||
if(MockPromise.race) { | ||
@@ -158,3 +170,3 @@ if (MockPromise.race !== fakeRace) { | ||
}; | ||
MockPromise.prototype.initialize = function(outerCallback) { | ||
@@ -246,3 +258,3 @@ var self = this; | ||
var raceFinished = false; | ||
if(promises.length === 0) { resolve(); } | ||
@@ -313,6 +325,6 @@ promises.forEach(function(promise) { | ||
function resolvePromise(promise, value, fulfilledHandler, errorHandler, progressHandler) { | ||
if(value && isFunction(value.then)) { | ||
if (isFulfilled(value) || isRejected(value)) { | ||
extend(promise, value); | ||
} else { | ||
if (value && isFunction(value.then)) { | ||
promise._returnedMockPromise = value; | ||
if (!isFulfilled(value) && !isRejected(value)) { | ||
each(contractsTracker.forPromise(promise), function(contract) { | ||
@@ -319,0 +331,0 @@ contractsTracker.addIfUnique(extend(contract, {promise: value})); |
{ | ||
"name": "mock-promises", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"author": "Charles Hansen <chansen87@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -66,3 +66,3 @@ #Mock Promises | ||
###Promise Resolution Policy | ||
Promises often lead to other promises, for example, `promise.then(function1).then(function2)`, so we had to decide what happens to the `function2` on a promise when you execute the `function1`. We have chosen to force the user to explicitly ask for each callback to be executed, so that they do not accidentally execute callacks without realizing it. Even `tick` will only go down one level of the chain unless the user specifies the number of levels. To manually go down a promise chain, you can use `iterateForPromise`. | ||
Promises often lead to other promises, for example, `promise.then(function1).then(function2)`, so we had to decide what happens to the `function2` on a promise when you execute the `function1`. We have chosen to encourage the user to explicitly ask for each callback to be executed, so that they do not accidentally execute callacks without realizing it. Even `tick` will only go down one level of the chain unless the user specifies the number of levels. We have recently provided `tickAllTheWay`, but its use is discouraged in most circumstances. | ||
@@ -89,2 +89,5 @@ ##API | ||
###tickAllTheWay() | ||
Repeats the `tick` procedure until there are no more resolved or rejected promises with unexectued handlers. This method is discouraged when testing code that you control. Using `tick` by itself with a specific count leads to much better understanding of your code flow and fewer potential race conditions. | ||
###executeForPromise(mockedPromise) | ||
@@ -91,0 +94,0 @@ Executes all fulfillmentHandlers if the mocked promise is resolved. Executes all rejectionHandlers if the mocked promise is rejected. Will not execute handlers that have already been executed. |
41788
856
184