From e8021e44021e769e1eed4dfdd85856b365287870 Mon Sep 17 00:00:00 2001 From: Grant Snodgrass Date: Fri, 16 Dec 2016 19:16:45 -0500 Subject: [PATCH] Update for Chai v4.0 Closes #157. Closes #198. --- .travis.yml | 2 +- lib/chai-as-promised.js | 19 ++++++++++++------- package.json | 4 ++-- test/should-eventually.coffee | 8 +++++--- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 49ae163..a970f65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/chai-as-promised.js b/lib/chai-as-promised.js index 1cf18b3..2c2b3de 100644 --- a/lib/chai-as-promised.js +++ b/lib/chai-as-promised.js @@ -101,6 +101,7 @@ module.exports = (chai, utils) => { ); module.exports.transferPromiseness(this, derivedPromise); + return this; }); property("rejected", function () { @@ -123,6 +124,7 @@ module.exports = (chai, utils) => { ); module.exports.transferPromiseness(this, derivedPromise); + return this; }); method("rejectedWith", function (errorLike, errMsgMatcher, message) { @@ -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) { @@ -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) { @@ -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); }); }); @@ -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); }); } }); @@ -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 => { @@ -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. diff --git a/package.json b/package.json index 17a761b..785a770 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test/should-eventually.coffee b/test/should-eventually.coffee index 417570d..109e0ca 100644 --- a/test/should-eventually.coffee +++ b/test/should-eventually.coffee @@ -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 @@ -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)