Skip to content

Commit

Permalink
Allow chaining tests and promises.
Browse files Browse the repository at this point in the history
- `.fulfilled`, `.not.rejected` and `.not.rejectedWith` when successful:

  * The promise they return is fulfilled with the same value as the
    promise they were testing.

- When `.not.fulfilled`, `.rejected` and `.rejectedWith` are successful:

  * The promise they return is fulfilled with the rejection
    reason.

In all cases, when they fail, the promise they return is rejected and
has for reason the assertion that failed.

The changes above make it so that the `object` flag is automatically
set when the promise returned is resolved, and thus also allows
chaining.

This fixes chaijs#113.
  • Loading branch information
lddubeau committed Sep 15, 2016
1 parent 828c2d2 commit 1e629d3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/chai-as-promised.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
var that = this;
var derivedPromise = getBasePromise(that).then(
function (value) {
that._obj = value;
assertIfNegated(that,
"expected promise not to be fulfilled but it was fulfilled with #{act}",
{ actual: value });
Expand All @@ -115,6 +114,7 @@
assertIfNotNegated(that,
"expected promise to be fulfilled but it was rejected with #{act}",
{ actual: reason });
return reason;
}
);

Expand All @@ -125,7 +125,6 @@
var that = this;
var derivedPromise = getBasePromise(that).then(
function (value) {
that._obj = value;
assertIfNotNegated(that,
"expected promise to be rejected but it was fulfilled with #{act}",
{ actual: value });
Expand Down Expand Up @@ -183,9 +182,8 @@
expected = desiredReason;
}

that._obj = value;

assertIfNotNegated(that, assertionMessage, { expected: expected, actual: value });
return value;
},
function (reason) {
if (Constructor) {
Expand Down Expand Up @@ -223,6 +221,7 @@
desiredReason,
reason);
}
return reason;
}
);

Expand Down

0 comments on commit 1e629d3

Please sign in to comment.