Apply this transform using jscodeshift to remove most chai-as-promised assertions.
Note: this codemod does not cover all of the
assert.eventually
cases, but they should be easy to add.
There's really no alternative to defining the function assert.isRejected
. The following should approximate the functionallity from chai-as-promised.
var chai = require('chai');
chai.assert.isRejected = function isRejected(promise, expected) {
return new Assertion(promise).to.be.rejectedWith(expected);
};
Assertion.addMethod('isRejected', function expectedRejection(promise, expected) {
var promise = this.then ? this : this._obj;
return promise
.then(function(actual) {
this.assert(
false,
'expected #{this} to be rejected but it was fulfilled with #{act}',
null,
expected,
actual
);
return actual;
}.bind(this),
function(reason) {
if (expected) {
if (expected instanceof RegExp || typeof expected === 'string') {
this.match(reason, expected);
}
if (expected instanceof Error) {
this.instanceOf(reason, expected);
}
}
}.bind(this));
});