Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Chai@4 - Fix assertions broken by Chai 4.0 #157

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/chai-as-promised.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module.exports = function (chai, utils) {
);

module.exports.transferPromiseness(that, derivedPromise);
return that;
});

property("rejected", function () {
Expand All @@ -124,6 +125,7 @@ module.exports = function (chai, utils) {
);

module.exports.transferPromiseness(that, derivedPromise);
return that;
});

method("rejectedWith", function (errorLike, errMsgMatcher, message) {
Expand All @@ -135,8 +137,7 @@ module.exports = function (chai, utils) {
if (errorLike === undefined && errMsgMatcher === undefined &&
message === undefined) {
/* jshint expr: true */
this.rejected;
return;
return this.rejected;
}

if (message !== undefined) {
Expand Down Expand Up @@ -224,14 +225,17 @@ module.exports = function (chai, utils) {
);

module.exports.transferPromiseness(that, derivedPromise);
return that;
});

property("eventually", function () {
utils.flag(this, "eventually", true);
return this;
});

method("notify", function (done) {
doNotify(getBasePromise(this), done);
return this;
});

method("become", function (value, message) {
Expand All @@ -249,7 +253,7 @@ module.exports = function (chai, utils) {
methodNames.forEach(function (methodName) {
Assertion.overwriteMethod(methodName, function (originalMethod) {
return function () {
doAsserterAsyncAndAddThen(originalMethod, this, arguments);
return doAsserterAsyncAndAddThen(originalMethod, this, arguments);
};
});
});
Expand All @@ -268,19 +272,19 @@ module.exports = function (chai, utils) {
getterName,
function (originalMethod) {
return function() {
doAsserterAsyncAndAddThen(originalMethod, this, arguments);
return doAsserterAsyncAndAddThen(originalMethod, this, arguments);
};
},
function (originalGetter) {
return function() {
doAsserterAsyncAndAddThen(originalGetter, this);
return doAsserterAsyncAndAddThen(originalGetter, this);
};
}
);
} else {
Assertion.overwriteProperty(getterName, function (originalGetter) {
return function () {
doAsserterAsyncAndAddThen(originalGetter, this);
return doAsserterAsyncAndAddThen(originalGetter, this);
};
});
}
Expand All @@ -290,7 +294,8 @@ module.exports = function (chai, utils) {
// Since we're intercepting all methods/properties, we need to just pass through if they don't want
// `eventually`, or if we've already fulfilled the promise (see below).
if (!utils.flag(assertion, "eventually")) {
return asserter.apply(assertion, args);
asserter.apply(assertion, args);
return assertion;
}

var derivedPromise = getBasePromise(assertion).then(function (value) {
Expand All @@ -311,6 +316,7 @@ module.exports = function (chai, utils) {
});

module.exports.transferPromiseness(assertion, derivedPromise);
return assertion;
}

///////
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"check-error": "^1.0.2"
},
"peerDependencies": {
"chai": ">= 2.1.2 < 4"
"chai": ">= 2.1.2 < 5"
},
"devDependencies": {
"chai": "^3.0.0",
"chai": "^4.0.0",
"coffee-script": "1.10.0",
"ecstatic": "^1.3.1",
"glob": "^6.0.1",
Expand Down
4 changes: 2 additions & 2 deletions test/should-eventually.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe "Fulfillment value assertions:", =>
fulfilledPromise(foo: "baz").should.not.eventually.deep.equal(foo: "bar").notify(done)
it ".eventually.not.deep.equal({ foo: 'bar' })", (done) =>
fulfilledPromise(foo: "baz").should.eventually.not.deep.equal(foo: "bar").notify(done)
it ".eventually.have.deep.property('foo.bar')", (done) =>
fulfilledPromise(foo: bar: "baz").should.eventually.have.deep.property("foo.bar", "baz").notify(done)
it ".eventually.have.nested.property('foo.bar')", (done) =>
fulfilledPromise(foo: bar: "baz").should.eventually.have.nested.property("foo.bar", "baz").notify(done)
it ".eventually.contain('foo')", (done) =>
fulfilledPromise(["foo", "bar"]).should.eventually.contain("foo").notify(done)
it ".not.eventually.contain('foo')", (done) =>
Expand Down