Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chaijs/chai-http
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: febebbd96de452ff0cab02ef3998dd987b9aee90
Choose a base ref
...
head repository: chaijs/chai-http
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1345021daad2c7b0fbac9fe5c541f55802795f33
Choose a head ref
  • 15 commits
  • 9 files changed
  • 5 contributors

Commits on Feb 3, 2016

  1. Improved the browser build

    Made three improvements to the browser build:
    
    1. It now builds _two_ browser bundles, one minified (49kb) and one unminified (129kb)
    2. It now builds source maps, which makes debugging in a browser easier
    3. `npm start` now runs with `--watch`, so it automatically does _fast_ differential rebuilds when any source files change
    JamesMessinger committed Feb 3, 2016
    Copy the full SHA
    7cb4962 View commit details
  2. Copy the full SHA
    e62a351 View commit details
  3. Merge pull request #73 from BigstickCarpet/better-browser-build

    Improved the browser build
    keithamus committed Feb 3, 2016
    Copy the full SHA
    e3b766c View commit details

Commits on Mar 11, 2016

  1. Fix 'passsword' typo

    sambostock committed Mar 11, 2016
    Copy the full SHA
    c158306 View commit details
  2. Copy the full SHA
    fac5372 View commit details
  3. Merge pull request #80 from sambostock/add-done-to-documentation

    Document asynchronous caveat
    keithamus committed Mar 11, 2016
    Copy the full SHA
    3fd809c View commit details

Commits on May 13, 2016

  1. Update README.md

    cjbramble committed May 13, 2016
    Copy the full SHA
    bc7e843 View commit details

Commits on May 15, 2016

  1. Merge pull request #90 from cjbrambo/master

    Update README.md
    keithamus committed May 15, 2016
    Copy the full SHA
    3626212 View commit details

Commits on Jun 10, 2016

  1. Copy the full SHA
    4b33336 View commit details
  2. refactor: update superagent to ^2.0.0

    BREAKING CHANGE:
    
    This update features some breaking changes from superagent, for more, read
    https://github.com/visionmedia/superagent/blob/master/History.md#200
    keithamus committed Jun 10, 2016
    Copy the full SHA
    288d9be View commit details
  3. chore(package): update qs to ^6.2.0

    BREAKING CHANGE:
    
    Drop support for old versions of Node (<4.0). Only Node LTS and stable are supported
    keithamus committed Jun 10, 2016
    Copy the full SHA
    21f84e4 View commit details
  4. Copy the full SHA
    6d73652 View commit details
  5. Merge pull request #99 from keithamus/update-all-the-things

    Update all the things
    keithamus authored Jun 10, 2016
    Copy the full SHA
    3083ab1 View commit details
  6. chore: build for 3.0.0

    keithamus committed Jun 10, 2016
    Copy the full SHA
    4dcd072 View commit details
  7. Merge pull request #100 from keithamus/3.0.0

    chore: build for 3.0.0
    keithamus authored Jun 10, 2016
    Copy the full SHA
    1345021 View commit details
Showing with 1,499 additions and 882 deletions.
  1. +2 −2 .travis.yml
  2. +37 −42 README.md
  3. +1,087 −739 dist/chai-http.js
  4. +69 −0 dist/chai-http.js.map
  5. +166 −0 dist/chai-http.min.js
  6. +69 −0 dist/chai-http.min.js.map
  7. +42 −83 lib/request.js
  8. +27 −15 package.json
  9. +0 −1 test/request.js
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- 0.1
- 0.11
- 4
- stable
deploy:
provider: npm
email:
79 changes: 37 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ To do this, you must first
construct a request to an application or url.

Upon construction you are provided a chainable api that
allow to you specify the http VERB request (get, post, etc)
allows you to specify the http VERB request (get, post, etc)
that you wish to invoke.

#### Application / Server
@@ -80,7 +80,7 @@ json, or even file attachments added to it, all with a simple API:
chai.request(app)
.put('/user/me')
.set('X-API-Key', 'foobar')
.send({ passsword: '123', confirmPassword: '123' })
.send({ password: '123', confirmPassword: '123' })
```

```js
@@ -120,12 +120,45 @@ To make the request and assert on its response, the `end` method can be used:
```js
chai.request(app)
.put('/user/me')
.send({ passsword: '123', confirmPassword: '123' })
.send({ password: '123', confirmPassword: '123' })
.end(function (err, res) {
expect(err).to.be.null;
expect(res).to.have.status(200);
});
```
##### Caveat
Because the `end` function is passed a callback, assertions are run
asynchronously. Therefore, a mechanism must be used to notify the testing
framework that the callback has completed. Otherwise, the test will pass before
the assertions are checked.

For example, in the [Mocha test framework](http://mochajs.org/), this is
accomplished using the
[`done` callback](https://mochajs.org/#asynchronous-code), which signal that the
callback has completed, and the assertions can be verified:

```js
it('fails, as expected', function(done) { // <= Pass in done callback
chai.request('http://localhost:8080')
.get('/')
.end(function(err, res) {
expect(res).to.have.status(123);
done(); // <= Call done to signal callback end
});
}) ;

it('succeeds silently!', function() { // <= No done callback
chai.request('http://localhost:8080')
.get('/')
.end(function(err, res) {
expect(res).to.have.status(123); // <= Test completes before this runs
});
}) ;
```

When `done` is passed in, Mocha will wait until the call to `done()`, or until
the [timeout](http://mochajs.org/#timeouts) expires. `done` also accepts an
error parameter when signaling completion.

#### Dealing with the response - Promises

@@ -135,7 +168,7 @@ and chaining of `then`s becomes possible:
```js
chai.request(app)
.put('/user/me')
.send({ passsword: '123', confirmPassword: '123' })
.send({ password: '123', confirmPassword: '123' })
.then(function (res) {
expect(res).to.have.status(200);
})
@@ -183,44 +216,6 @@ agent
})
```

### .then (resolveCb, rejectCb)

* **@param** _{Function}_ resolveCB
* **@cb** {Response}
* **@param** _{Function}_ rejectCB
* **@cb** {Error}

Invoke the request to to the server. The response
will be passed as a parameter to the resolveCb,
while any errors will be passed to rejectCb.

```js
chai.request(app)
.get('/')
.then(function (res) {
expect(res).to.have.status(200);
}, function (err) {
throw err;
});
```

### .catch (rejectCb)

* **@param** _{Function}_ rejectCB
* **@cb** {Error}

Invoke the request to to the server, catching any
errors with this callback. Behaves the same as
Promises.

```js
chai.request(app)
.get('/')
.catch(function (err) {
throw err;
});
```

## Assertions

The Chai HTTP module provides a number of assertions
Loading