title: Simple Mocha/Chai test for Nodejs/Express API
body: <p>I'm trying to build a test set for my API, which was developed with nodejs/express, with mocha/chai. Basically, the index returns a simple string that I know it's working because I can see on my browser:</p>
  
  <pre><code>router.get('/', function(req, res, next) {
      res.send('Hello World from Eclipse');
  });
  </code></pre>
  
  <p>Then I followed this <a href="https://codeforgeek.com/2015/07/unit-testing-nodejs-application-using-mocha/" rel="nofollow">tutorial</a> to build this test:</p>
  
  <pre><code>var supertest = require("supertest");
  var should = require("should");
  
  // This agent refers to PORT where program is runninng.
  
  var server = supertest.agent("http://localhost:5000");
  
  // UNIT test begin
  
  describe("SAMPLE unit test",function(){
  
    // #1 should return home page
  
    it("should return home page",function(done){
  
      // calling home page api
      server
      .get("/")
      .expect("Content-type",/json/)
      .expect(200) // THis is HTTP response
      .end(function(err,res){
        // HTTP status should be 200
        res.status.should.equal(200);
        // Error key should be false.
        res.body.error.should.equal(false);
        done();
      });
    });
  
  });
  </code></pre>
  
  <p>I can see on the log of my server that the address is been called, however, the test always say that it cannot read property 'should' of undefined, on the line where I have 'res.status.should.equal(200);'. Probably because 'res' is undefined. In other words, no answer from the API.</p>
  
  <p>Am I missing something here? I running mocha with no arguments...</p>