Simple documentation update. Closes issue #11 #27

Merged
merged 3 commits into from Oct 7, 2012

Projects

None yet

2 participants

@mfrobben
Contributor
mfrobben commented Oct 6, 2012

No description provided.

Matthew Robben added some commits Oct 6, 2012
@tj tj and 1 other commented on an outdated diff Oct 6, 2012
@@ -50,6 +50,26 @@ describe('GET /users', function(){
})
```
+ 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
@tj
tj Oct 6, 2012 Member

this will call done() twice, it needs to be if (err) return done(err), though in this case it could just be.end(done)`

@mfrobben
mfrobben Oct 7, 2012 Contributor

Sorry bout that, sped through writing the update and pull request while on a flight. Updated the readme in the repo. The reason I don't want to use the end(done()) syntax is because in my test cases, I will use expect(200, done) if I'm just validating the response code and end(function(err, res){}) when I want to check something in the response body or header AND validate the response code.

Thx,
~M

On Oct 6, 2012, at 12:39 PM, TJ Holowaychuk notifications@github.com wrote:

In Readme.md:

@@ -50,6 +50,26 @@ describe('GET /users', function(){
})


+  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
this will call done() twice, it needs to be if (err) return done(err), though in this case it could just be.end(done)`


Reply to this email directly or view it on GitHub.

Matthew Robben Fixing doc bug. 55d7274
@tj tj commented on the diff Oct 7, 2012
Readme.md
@@ -50,6 +50,26 @@ describe('GET /users', function(){
})
```
+ 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)
+ return done(err) // if response is 500 or 404, test case will fail
@tj
tj Oct 7, 2012 Member

doesn't apply only to 500 / 404, so this comment is wrong but ill fix

@tj tj merged commit 07200e3 into visionmedia:master Oct 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment