mock-promises
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -27,3 +27,3 @@ (function (root, factory) { | ||
var MockPromise, OriginalPromise, originalThen, originalAll; | ||
var MockPromise, OriginalPromise, originalThen, originalAll, originalRace; | ||
@@ -54,2 +54,9 @@ var MockPromises = function() { | ||
} | ||
if(MockPromise.race) { | ||
if (MockPromise.race !== fakeRace) { | ||
originalRace = MockPromise.race; | ||
} | ||
MockPromise.race = fakeRace; | ||
} | ||
@@ -97,2 +104,4 @@ }; | ||
MockPromise.race = fakeRace; | ||
MockPromise.prototype.inspect = function() { | ||
@@ -175,2 +184,23 @@ return {value: self.resolvedValue, reason: self.rejectedValue}; | ||
var fakeRace = function(promises){ | ||
return new MockPromise(function(resolve, reject) { | ||
var raceFinished = false; | ||
promises.forEach(function(promise) { | ||
promise.then( | ||
function(val){ | ||
if (!raceFinished) { | ||
raceFinished = true; | ||
resolve(val) | ||
} | ||
}, function(val){ | ||
if (!raceFinished) { | ||
raceFinished = true; | ||
reject(val) | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
var self = this; | ||
@@ -181,3 +211,3 @@ each([ | ||
self[methodName] = function() { | ||
return contractsTracker[methodName].apply(contractsTracker, arguments) | ||
return contractsTracker[methodName].apply(contractsTracker, arguments); | ||
} | ||
@@ -184,0 +214,0 @@ }); |
{ | ||
"name": "mock-promises", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"author": "Charles Hansen <chansen87@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -52,3 +52,3 @@ #Mock Promises | ||
## Native Promises | ||
If you are using Native promises, mock promises needs to mock out the constructor, which requires `getMockPromise`. This method is doing a lot more than `install`, and is still in development. Mock Promises currently has significantly reduced functionality with Native Promises. | ||
If you are using Native promises, mock promises needs to mock out the constructor, which requires `getMockPromise`. This method is doing a lot more than `install` and may have slightly different behavior than mocking out promises from libraries. | ||
@@ -55,0 +55,0 @@ ```js |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19766
325