Skip to content

Commit 1345021

Browse files
authoredJun 10, 2016
Merge pull request #100 from keithamus/3.0.0
chore: build for 3.0.0
2 parents 3083ab1 + 4dcd072 commit 1345021

7 files changed

+1193
-854
lines changed
 

‎README.md

-40
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ chai.request(app)
126126
expect(res).to.have.status(200);
127127
});
128128
```
129-
130129
##### Caveat
131-
132130
Because the `end` function is passed a callback, assertions are run
133131
asynchronously. Therefore, a mechanism must be used to notify the testing
134132
framework that the callback has completed. Otherwise, the test will pass before
@@ -218,44 +216,6 @@ agent
218216
})
219217
```
220218

221-
### .then (resolveCb, rejectCb)
222-
223-
* **@param** _{Function}_ resolveCB
224-
* **@cb** {Response}
225-
* **@param** _{Function}_ rejectCB
226-
* **@cb** {Error}
227-
228-
Invoke the request to to the server. The response
229-
will be passed as a parameter to the resolveCb,
230-
while any errors will be passed to rejectCb.
231-
232-
```js
233-
chai.request(app)
234-
.get('/')
235-
.then(function (res) {
236-
expect(res).to.have.status(200);
237-
}, function (err) {
238-
throw err;
239-
});
240-
```
241-
242-
### .catch (rejectCb)
243-
244-
* **@param** _{Function}_ rejectCB
245-
* **@cb** {Error}
246-
247-
Invoke the request to to the server, catching any
248-
errors with this callback. Behaves the same as
249-
Promises.
250-
251-
```js
252-
chai.request(app)
253-
.get('/')
254-
.catch(function (err) {
255-
throw err;
256-
});
257-
```
258-
259219
## Assertions
260220

261221
The Chai HTTP module provides a number of assertions

‎dist/chai-http.js

+1,082-740
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/chai-http.js.map

+15-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/chai-http.min.js

+42-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/chai-http.min.js.map

+16-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/request.js

+37-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var http = require('http')
2525
* construct a request to an application or url.
2626
*
2727
* Upon construction you are provided a chainable api that
28-
* allow to you specify the http VERB request (get, post, etc)
28+
* allows you to specify the http VERB request (get, post, etc)
2929
* that you wish to invoke.
3030
*
3131
* #### Application / Server
@@ -61,7 +61,7 @@ var http = require('http')
6161
* chai.request(app)
6262
* .put('/user/me')
6363
* .set('X-API-Key', 'foobar')
64-
* .send({ passsword: '123', confirmPassword: '123' })
64+
* .send({ password: '123', confirmPassword: '123' })
6565
* ```
6666
*
6767
* ```js
@@ -101,12 +101,45 @@ var http = require('http')
101101
* ```js
102102
* chai.request(app)
103103
* .put('/user/me')
104-
* .send({ passsword: '123', confirmPassword: '123' })
104+
* .send({ password: '123', confirmPassword: '123' })
105105
* .end(function (err, res) {
106106
* expect(err).to.be.null;
107107
* expect(res).to.have.status(200);
108108
* });
109109
* ```
110+
* ##### Caveat
111+
* Because the `end` function is passed a callback, assertions are run
112+
* asynchronously. Therefore, a mechanism must be used to notify the testing
113+
* framework that the callback has completed. Otherwise, the test will pass before
114+
* the assertions are checked.
115+
*
116+
* For example, in the [Mocha test framework](http://mochajs.org/), this is
117+
* accomplished using the
118+
* [`done` callback](https://mochajs.org/#asynchronous-code), which signal that the
119+
* callback has completed, and the assertions can be verified:
120+
*
121+
* ```js
122+
* it('fails, as expected', function(done) { // <= Pass in done callback
123+
* chai.request('http://localhost:8080')
124+
* .get('/')
125+
* .end(function(err, res) {
126+
* expect(res).to.have.status(123);
127+
* done(); // <= Call done to signal callback end
128+
* });
129+
* }) ;
130+
*
131+
* it('succeeds silently!', function() { // <= No done callback
132+
* chai.request('http://localhost:8080')
133+
* .get('/')
134+
* .end(function(err, res) {
135+
* expect(res).to.have.status(123); // <= Test completes before this runs
136+
* });
137+
* }) ;
138+
* ```
139+
*
140+
* When `done` is passed in, Mocha will wait until the call to `done()`, or until
141+
* the [timeout](http://mochajs.org/#timeouts) expires. `done` also accepts an
142+
* error parameter when signaling completion.
110143
*
111144
* #### Dealing with the response - Promises
112145
*
@@ -116,7 +149,7 @@ var http = require('http')
116149
* ```js
117150
* chai.request(app)
118151
* .put('/user/me')
119-
* .send({ passsword: '123', confirmPassword: '123' })
152+
* .send({ password: '123', confirmPassword: '123' })
120153
* .then(function (res) {
121154
* expect(res).to.have.status(200);
122155
* })

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chai-http",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"description": "Extend Chai Assertion library with tests for http apis",
55
"author": "Jake Luer <jake@alogicalparadox.com>",
66
"keywords": [

0 commit comments

Comments
 (0)
Please sign in to comment.