Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bumping version and updating README.

  • Loading branch information...
commit 86956fa6b77de7ef34b638ac76be8c947922d9d0 1 parent 0dda7d3
@domenic authored
Showing with 44 additions and 9 deletions.
  1. +43 −8 README.md
  2. +1 −1  package.json
View
51 README.md
@@ -20,7 +20,7 @@ doSomethingAsync().then(
you can write code that expresses what you really mean:
```javascript
-doSomethingAsync().should.eventually.equal("foo").then(done, done);
+doSomethingAsync().should.eventually.equal("foo").notify(done);
```
or if you have a testing framework that follows the [UncommonJS specification][uncommonjs] for handling promises,
@@ -30,7 +30,7 @@ simply
return doSomethingAsync().should.eventually.equal("foo");
```
-## How to Use
+## How to Use: `should`/`expect` Interface
The most powerful extension provided by Chai as Promised is the `eventually` property. With it, you can transform any
existing Chai assertion into one that acts on a promise:
@@ -41,29 +41,64 @@ existing Chai assertion into one that acts on a promise:
// becomes
return promiseFor(2 + 2).should.eventually.equal(4);
-({ foo: "bar" }).should.have.property("foo");
+
+expect({ foo: "bar" }).to.have.property("foo");
// becomes
-return promiseFor({ foo: "bar" }).should.eventually.have.property("foo");
+return expect(promiseFor({ foo: "bar" })).to.eventually.have.property("foo");
```
-There are also a few promise-specific extensions, grouped here as synonymic blocks:
+There are also a few promise-specific extensions, grouped here as synonymic blocks (with the usual `expect` equivalents
+also available):
```javascript
return promise.should.be.fulfilled;
-return promise.should.be.rejected;
-return promise.should.be.broken;
-
return promise.should.eventually.eql("foo");
return promise.should.become("foo");
+return promise.should.be.rejected;
+return promise.should.be.broken;
+
return promise.should.be.rejected.with(Error);
return promise.should.be.broken.with(Error);
// Note: other variants of Chai's existing `throw` assertion work too.
```
+## How to Use: `assert` Interface
+
+As with the `should`/`expect` interface, Chai as Promised provides an `eventually` extender to `chai.assert`, allowing
+any existing Chai assertion to be used on a promise:
+
+```javascript
+assert.equal(2 + 2, 4, "This had better be true");
+
+// becomes
+return assert.eventually.equal(promiseFor(2 + 2), 4, "This had better be true, eventually");
+```
+
+And there are, of course, promise-specific extensions:
+
+```javascript
+return assert.isFulfilled(promise, "optional message");
+
+return assert.eventually.deepEqual(promise, "foo");
+return assert.becomes(promise, "foo");
+
+return assert.eventually.notDeepEqual(promise, "foo");
+return assert.doesNotBecome(promise, "foo");
+
+return assert.isRejected(promise, "optional message");
+return assert.isBroken(promise, "optional message");
+
+return assert.isRejected(promise, Error, "optional message");
+return assert.isBroken(promise, Error, "optional message");
+
+return assert.isRejected(promise, /error message matcher/, "optional message");
+return assert.isBroken(promise, /error message matcher/, "optional message");
+```
+
## Installation and Usage
### Node
View
2  package.json
@@ -6,7 +6,7 @@
"testing",
"promises"
],
- "version": "1.2.0",
+ "version": "2.0.0",
"author": "Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)",
"repository": {
"type": "git",
Please sign in to comment.
Something went wrong with that request. Please try again.