title: Mocha chai-http response always returns null
body: <p>I'm testing a server response in Node.js via mocha chai-http.
  <strong>The response I get is always null</strong>. However, When I run requests regularly without mocha test runner, Everything is fine.</p>
  
  <p>This is the sever code:</p>
  
  <pre><code>var Babble = { messages: new Array() , users: new Array(),userCount:0 }; // 
  
  var http = require('http');
  var urlUtil = require('url');
  var queryUtil = require('querystring');
  
  var Babble = { messages: new Array() , users: new Array(),userCount:0 }; // Data object to save all chat logs
  var server = http.createServer(function(request, response) {
      var strData,name,index;
      response.setHeader('Access-Control-Allow-Origin', '*');
      if (request.method === 'GET') {
          var url = urlUtil.parse(request.url);
          var data = queryUtil.parse(url.query);
          console.log(data.message);
          if (!data.message) {
              response.writeHead(400);
          }
          response.end();
      } else if (request.method === 'POST') {
          var requestBody = '';
          request.on('data', function(chunk) {
                  requestBody += chunk.toString();
          });
          request.on('end', function() {
              var data = queryUtil.parse(requestBody);
              strData = JSON.stringify(data);
              // Handle different requests
  
                  ...
  
              response.end(JSON.stringify(Babble));
  
              }   
          });
  });
  
      module.exports = {server,Babble};
  </code></pre>
  
  <p>And this is the mocha chai-http test code:</p>
  
  <pre><code>var module = require('./testedServer');
  var assert = require('assert');
  
  var chai = require('chai')
    , chaiHttp = require('chai-http');
  
  chai.use(chaiHttp);
  
   describe('Check receiving data from server:', function() {
  
                  beforeEach(function() {
  
                          module.server.listen(9099);
  
                  });
  
                  it('Should receive a non-null object containing the chat logs', function(done) {
  
                          chai.request('http://localhost:9099')
                                  .post('/')
                                  .send(
                                  'poll0,0/Annonymous.'
                          ).end(function(res){
                                          console.log(res);
                                          assert.equal(res != null,true,"Error: test has failed - server response is null");
                                          done();
                          });
  
                  });
  
                  afterEach(function() {
  
                          // runs after each test in this block
  
                          module.server.close();
  
                  });
  
          });
  </code></pre>
  
  <p>I think I pronounced the request wrong. </p>