From be8a80667d4198be27c7c7044d7bf7064b73235f Mon Sep 17 00:00:00 2001 From: Matthew Robben Date: Sat, 6 Oct 2012 08:12:52 -0400 Subject: [PATCH 1/3] Updating readme to explain use of .end() with mocha. --- Readme.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Readme.md b/Readme.md index 62e1bf25..778d302d 100644 --- a/Readme.md +++ b/Readme.md @@ -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! From 504675bcdfd0313753528fcd8814a49b0c5db9cd Mon Sep 17 00:00:00 2001 From: Matthew Robben Date: Sat, 6 Oct 2012 09:07:30 -0400 Subject: [PATCH 2/3] Formatting fix. --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 778d302d..f004dc91 100644 --- a/Readme.md +++ b/Readme.md @@ -50,9 +50,9 @@ describe('GET /users', function(){ }) ``` - If you are using the `.end()` syntax with mocha, `expect()` assertions that fail will + 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: + order to fail the test case, you will need to rethrow or pass `err` to `done()`, as follows: ```js describe('GET /users', function(){ From 55d7274b8a64a57c4c7397705caed854216cc5b6 Mon Sep 17 00:00:00 2001 From: Matthew Robben Date: Sun, 7 Oct 2012 08:44:05 -0400 Subject: [PATCH 3/3] Fixing doc bug. --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index f004dc91..0de3ec7b 100644 --- a/Readme.md +++ b/Readme.md @@ -63,7 +63,7 @@ describe('GET /users', function(){ .expect(200) .end(function(err, res){ if (err) - done(err) // if response is 500 or 404, test case will fail + return done(err) // if response is 500 or 404, test case will fail done() }); })