Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mock-promises

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-promises - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

gulpfile.js

76

lib/mock-promises.js

@@ -27,2 +27,54 @@ (function (root, factory) {

var getValue = function(promise) {
if(isFunction(promise.inspect)) {
//Q, mockedNative
return promise.inspect().value;
}
if(isFunction(promise.value)) {
//bluebird
return promise.value();
}
if(promise.hasOwnProperty('_result')) {
//es6-promise
return promise._result;
}
};
var getReason = function(promise) {
if(isFunction(promise.inspect)) {
//Q, mockedNative
return promise.inspect().reason;
}
if(isFunction(promise.reason)) {
//bluebird
return promise.reason();
}
if(promise.hasOwnProperty('_result')) {
//es6-promise
return promise._result;
}
};
var isFulfilled = function(promise) {
if(isFunction(promise.isFulfilled)) {
//Q, mockedNative
return promise.isFulfilled();
}
if(promise.hasOwnProperty('_state')) {
//es6-promise
return promise._state === 1;
}
};
var isRejected = function(promise) {
if(isFunction(promise.isRejected)) {
//Q, mockedNative
return promise.isRejected();
}
if(promise.hasOwnProperty('_state')) {
//es6-promise
return promise._state === 2;
}
};
var MockPromise, OriginalPromise, originalThen, originalAll, originalRace;

@@ -39,10 +91,2 @@

MockPromise.prototype.then = fakeThen;
if (!MockPromise.prototype.isFulfilled) {
//for es6Promises
MockPromise.prototype.inspect = function() {
return { value: this._result, reason: this._result };
};
MockPromise.prototype.isFulfilled = function(){return this._state === 1;}
MockPromise.prototype.isRejected = function(){return this._state === 2;}
}

@@ -122,3 +166,3 @@ if(MockPromise.all) {

}
}
};

@@ -133,3 +177,3 @@ var fakeReject = function(value) {

}
}
};

@@ -259,4 +303,4 @@ outerCallback(fakeResolve, fakeReject);

var value, nextValue, handler;
if(this.promise.isFulfilled()) {
value = this.promise.inspect().value;
if(isFulfilled(this.promise)) {
value = getValue(this.promise);
handler = this.fulfilledHandler;

@@ -273,4 +317,4 @@ if(handler) {

}
} else if(this.promise.isRejected()) {
value = this.promise.inspect().reason;
} else if(isRejected(this.promise)) {
value = getReason(this.promise);
handler = this.errorHandler;

@@ -374,3 +418,3 @@ if(handler) {

this.valueForPromise = function(promise) {
return promise.inspect().value;
return getValue(promise);
};

@@ -380,3 +424,3 @@

var resolvedContracts = this.filter(function(contract) {
return contract.promise.isFulfilled() || contract.promise.isRejected();
return isFulfilled(contract.promise) || isRejected(contract.promise);
});

@@ -383,0 +427,0 @@ each(resolvedContracts, function(contract) {

{
"name": "mock-promises",
"version": "0.4.1",
"version": "0.5.0",
"author": "Charles Hansen <chansen87@gmail.com>",

@@ -17,4 +17,3 @@ "license": "MIT",

"scripts": {
"pretest": "npm install -g mocha-server",
"test": "mocha-server spec/javascripts/mocha_examples_test.js -r lib/mock-promises.js spec/javascripts/support/expect.js"
"test": "./node_modules/mocha-server/bin/mocha-server spec/javascripts/mocha_examples_test.js -r lib/mock-promises.js spec/support/expect.js"
},

@@ -25,3 +24,15 @@ "keywords": [

"test"
]
],
"devDependencies": {
"bluebird": "^2.9.34",
"es6-promise": "^2.3.0",
"gulp": "^3.9.0",
"gulp-jasmine-browser": "^0.1.4",
"gulp-util": "^3.0.6",
"mocha-server": "^0.2.0",
"q": "^1.4.1",
"slimerjs": "^0.9.6",
"webpack": "^1.10.5",
"webpack-stream": "^2.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc