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

chai-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-as-promised - npm Package Compare versions

Comparing version 4.2.0 to 4.3.0

LICENSE.txt

7

lib/chai-as-promised.js

@@ -29,2 +29,6 @@ (function () {

chaiAsPromised.transformAsserterArgs = function (values) {
return values;
};
function chaiAsPromised(chai, utils) {

@@ -304,2 +308,5 @@ var Assertion = chai.Assertion;

utils.flag(assertion, "eventually", false);
return args ? chaiAsPromised.transformAsserterArgs(args) : args;
}).then(function (args) {
asserter.apply(assertion, args);

@@ -306,0 +313,0 @@

2

package.json

@@ -11,3 +11,3 @@ {

],
"version": "4.2.0",
"version": "4.3.0",
"author": "Domenic Denicola <d@domenic.me> (https://domenic.me)",

@@ -14,0 +14,0 @@ "license": "WTFPL",

@@ -48,3 +48,3 @@ <a href="http://promisesaplus.com/">

// becomes
return promiseFor(2 + 2).should.eventually.equal(4);
return Promise.resolve(2 + 2).should.eventually.equal(4);

@@ -55,3 +55,3 @@

// becomes
return expect(promiseFor({ foo: "bar" })).to.eventually.have.property("foo");
return expect(Promise.resolve({ foo: "bar" })).to.eventually.have.property("foo");
```

@@ -78,3 +78,3 @@

// becomes
return assert.eventually.equal(promiseFor(2 + 2), 4, "This had better be true, eventually");
return assert.eventually.equal(Promise.resolve(2 + 2), 4, "This had better be true, eventually");
```

@@ -126,2 +126,33 @@

### Transforming Arguments to the Asserters
Another advanced customization hook Chai as Promised allows is if you want to transform the arguments to the
asserters, possibly asynchronously. Here is a toy example:
```js
chaiAsPromised.transformAsserterArgs = function (args) {
return args.map(function (x) { return x + 1; });
}
Promise.resolve(2).should.eventually.equal(2); // will now fail!
Promise.resolve(2).should.eventually.equal(3); // will now pass!
```
The transform can even be asynchronous, returning a promise for an array instead of an array directly. An example
of that might be using `Promise.all` so that an array of promises becomes a promise for an array. If you do that,
then you can compare promises against other promises using the asserters:
```js
// This will normally fail, since within() only works on numbers.
Promise.resolve(2).should.eventually.be.within(Promise.resolve(1), Promise.resolve(6));
chaiAsPromised.transformAsserterArgs = function (args) {
return Promise.all(args);
};
// But now it will pass, since we transformed the array of promises for numbers into
// (a promise for) an array of numbers
Promise.resolve(2).should.eventually.be.within(Promise.resolve(1), Promise.resolve(6));
```
### Compatibility

@@ -128,0 +159,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