Permalink
Browse files

Updating readme to explain use of .end() with mocha.

  • Loading branch information...
1 parent c512e94 commit be8a80667d4198be27c7c7044d7bf7064b73235f Matthew Robben committed Oct 6, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 Readme.md
View
@@ -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!

0 comments on commit be8a806

Please sign in to comment.