Socket
Socket
Sign inDemoInstall

chai-as-promised

Package Overview
Dependencies
0
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

57

lib/chai-as-promised.js

@@ -24,6 +24,15 @@ (function (chaiAsPromised) {

function assertIsAboutPromise(assertion) {
if (typeof assertion._obj.then !== "function") {
throw new TypeError(utils.inspect(assertion._obj) + " is not a promise!");
}
if (typeof assertion._obj.pipe === "function") {
throw new TypeError("Chai as Promised is incompatible with jQuery's so-called “promises.” Sorry!");
}
}
function property(name, asserter) {
Object.defineProperty(Assertion.prototype, name, {
get: asserter,
configurable: true
utils.addProperty(Assertion.prototype, name, function () {
assertIsAboutPromise(this);
return asserter.apply(this, arguments);
});

@@ -33,3 +42,6 @@ }

function method(name, asserter) {
Assertion.prototype[name] = asserter;
utils.addMethod(Assertion.prototype, name, function () {
assertIsAboutPromise(this);
return asserter.apply(this, arguments);
});
}

@@ -268,7 +280,34 @@

} else if (propertyDescriptor.get) {
propertyDescriptor.get = function () {
return promiseToDoAsserter(function (assertion) {
return assertion[asserterName];
});
};
// This case is complicated by asserters that can be used as both chainers and as terminators, e.g.
// (5).should.not.be.an.instanceOf(Object) vs. (5).should.not.be.an("object"). In such cases the getter
// will return a function with its [[Prototype]] set to the assertion, with the function used in the
// terminator case and the assertion [[Prototype]] used in the chainer case.
var getterIsFunction = false;
try {
getterIsFunction = typeof propertyDescriptor.get.call({}) === "function";
} catch (e) { }
if (getterIsFunction) {
// If we've detected we're in the special case described above, we need to handle it specially:
// The getter should be for a function that calls the original function, and the function should
// have its [[Prototype]] set (via `__proto__`, ugh) to the augmented promise, which you can chain
// off of just like an assertion (but better).
propertyDescriptor.get = function () {
/*jshint proto:true */
function funcToBeGotten() {
var args = arguments;
return promiseToDoAsserter(function (assertion) {
return Function.prototype.apply.call(assertion[asserterName], assertion, args);
});
}
funcToBeGotten.__proto__ = augmentedPromise;
return funcToBeGotten;
};
} else {
propertyDescriptor.get = function () {
return promiseToDoAsserter(function (assertion) {
return assertion[asserterName];
});
};
}
}

@@ -275,0 +314,0 @@

3

package.json

@@ -9,3 +9,3 @@ {

],
"version": "3.0.0",
"version": "3.1.0",
"author": "Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)",

@@ -25,3 +25,2 @@ "repository": {

"test-browser-q": "coffee ./test/browser/runner q",
"test-browser-jquery": "coffee ./test/browser/runner jquery",
"test-browser-when": "coffee ./test/browser/runner when",

@@ -28,0 +27,0 @@ "test": "mocha",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc