Skip to content

Commit

Permalink
Updating readme to explain use of .end() with mocha.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Robben committed Oct 6, 2012
1 parent c512e94 commit be8a806
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Readme.md
Expand Up @@ -48,6 +48,26 @@ describe('GET /users', function(){
.expect(200, done);
})
})
```

If you are using the `.end()` syntax with mocha, `expect()` assertions that fail will
not throw - they will return the assertion as an error to the `.end()` callback. In
order to fail the test case, you will need to rethrow or pass `err` to `done`, as follows:

```js
describe('GET /users', function(){
it('respond with json', function(done){
request(app)
.get('/user')
.set('Accept', 'application/json')
.expect(200)
.end(function(err, res){
if (err)
done(err) // if response is 500 or 404, test case will fail
done()
});
})
})
```

Anything you can do with superagent, you can do with supertest - for example multipart file uploads!
Expand Down

0 comments on commit be8a806

Please sign in to comment.