title: Unit test logging (use mocha, supertest, and chai) of restful api built with express, node.js
body: <p>I write the a simple unit test with mocha, chai and supertest.</p>
  
  <pre><code>describe('controller.CWEManagementAPI', function () {
  it('should be able to say hello', function() { 
      var request = require('supertest')
      , express = require('express');
  
      var app = express();
  
      app.get('/user', function(req, res){
          res.send(201, { name: 'tobi' });
      });
  
      request(app)
      .get('/user')
      .set('Accept', 'application/json')
      .expect(200)
      .end(function(err, res){
          if (err) return done(err);
          console.log('test');
          assert.equal( res.body.name, 'tobi');
          done()
      });
  });
  });
  </code></pre>
  
  <p>But the problem is that : the <code>console.log('test')</code> is not executed.
  So I think the <code>assert.equal( res.body.name, 'tobi');</code> is not executed either.
  And so I write the code without unit testing, like :</p>
  
  <pre><code>var request = require('supertest')
  , express = require('express');
  
  var app = express();
  
  app.get('/user', function(req, res){
  res.send(201, { name: 'tobi' });
  });
  
  request(app)
     .get('/user')
     .expect('Content-Type', /json/)
     .expect('Content-Length', '20')
     .expect(201)
     .end(function(err, res){ 
      if (err) throw err;
      console.log(res.body.name);
      console.log('done');
      process.exit();
     });
  </code></pre>
  
  <p>And the <code>console.log()</code>  are all executed. so I don't know why the first code can not show the logging info.</p>