Skip to content

Commit

Permalink
Update for Chai v4.0
Browse files Browse the repository at this point in the history
Closes #157. Closes #198.
  • Loading branch information
meeber authored and domenic committed Jun 11, 2017
1 parent 16dde11 commit e8021e4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ node_js:
- 4
- stable
env:
# Can't figure out how to DRY this up: http://stackoverflow.com/q/22397300/3191
- CHAI_VERSION=^2.1.2
- CHAI_VERSION=^3.0.0
- CHAI_VERSION=^4.0.0
script:
- npm run lint
- npm run test-travis
19 changes: 12 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 = (chai, utils) => {
);

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

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

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

method("rejectedWith", function (errorLike, errMsgMatcher, message) {
Expand All @@ -134,9 +136,8 @@ module.exports = (chai, utils) => {
if (errorLike === undefined && errMsgMatcher === undefined &&
message === undefined) {
/* eslint-disable no-unused-expressions */
this.rejected;
return this.rejected;
/* eslint-enable no-unused-expressions */
return;
}

if (message !== undefined) {
Expand Down Expand Up @@ -220,14 +221,17 @@ module.exports = (chai, utils) => {
);

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

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 @@ -243,7 +247,7 @@ module.exports = (chai, utils) => {

methodNames.forEach(methodName => {
Assertion.overwriteMethod(methodName, originalMethod => function () {
doAsserterAsyncAndAddThen(originalMethod, this, arguments);
return doAsserterAsyncAndAddThen(originalMethod, this, arguments);
});
});

Expand All @@ -260,15 +264,15 @@ module.exports = (chai, utils) => {
Assertion.overwriteChainableMethod(
getterName,
originalMethod => function () {
doAsserterAsyncAndAddThen(originalMethod, this, arguments);
return doAsserterAsyncAndAddThen(originalMethod, this, arguments);
},
originalGetter => function () {
doAsserterAsyncAndAddThen(originalGetter, this);
return doAsserterAsyncAndAddThen(originalGetter, this);
}
);
} else {
Assertion.overwriteProperty(getterName, originalGetter => function () {
doAsserterAsyncAndAddThen(originalGetter, this);
return doAsserterAsyncAndAddThen(originalGetter, this);
});
}
});
Expand All @@ -278,7 +282,7 @@ module.exports = (chai, utils) => {
// `eventually`, or if we've already fulfilled the promise (see below).
if (!utils.flag(assertion, "eventually")) {
asserter.apply(assertion, args);
return;
return assertion;
}

const derivedPromise = getBasePromise(assertion).then(value => {
Expand All @@ -299,6 +303,7 @@ module.exports = (chai, utils) => {
});

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

// ### Now use the `Assertion` framework to build an `assert` interface.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"eslint": "^3.19.0"
},
"peerDependencies": {
"chai": ">= 2.1.2 < 4"
"chai": ">= 2.1.2 < 5"
},
"devDependencies": {
"chai": "^3.5.0",
"chai": "^4.0.2",
"coffee-script": "1.10.0",
"istanbul": "0.4.5",
"mocha": "^3.4.2"
Expand Down
8 changes: 5 additions & 3 deletions test/should-eventually.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ describe "Fulfillment value assertions:", =>
it ".eventually.not.deep.equal({ foo: 'bar' })", (done) =>
fulfilledPromise(foo: "baz").should.eventually.not.deep.equal(foo: "bar").notify(done)
return
it ".eventually.have.deep.property('foo.bar')", (done) =>
fulfilledPromise(foo: bar: "baz").should.eventually.have.deep.property("foo.bar", "baz").notify(done)
return
it ".eventually.contain('foo')", (done) =>
fulfilledPromise(["foo", "bar"]).should.eventually.contain("foo").notify(done)
return
Expand All @@ -72,6 +69,11 @@ describe "Fulfillment value assertions:", =>
fulfilledPromise([]).should.eventually.be.an.instanceOf(Array).notify(done)
return

if Object.prototype.should.nested
it ".eventually.have.nested.property('foo.bar')", (done) =>
fulfilledPromise(foo: bar: "baz").should.eventually.have.nested.property("foo.bar", "baz").notify(done)
return

describe "Chaining:", =>
it ".eventually.be.ok.and.equal(42)", (done) =>
fulfilledPromise(42).should.eventually.be.ok.and.equal(42).notify(done)
Expand Down

0 comments on commit e8021e4

Please sign in to comment.