title: How to unit test a pool connection?
body: <p>I would like to unit test (mocha &amp; chai) a pool connection (mysql) in my node.js app. I don't know if I'm using the tests in the correct way and, if so, why they are always qualified as "pending".</p>
  
  <p>Giving the following code, how would I test it?</p>
  
  <pre><code>var pool = mysql.createPool({
      connectionLimit: 100,
      host: 'localhost',
      user: 'userName',
      password: 'userPass',
      database: 'userDatabase',
      debug: false
  });
  </code></pre>
  
  <p>I have tried in many ways but it doesn't seem to work. Best I got was this:</p>
  
  <pre><code>describe("Database", function () {
      describe("Connection", function () {
          it("Should connect without an error", pool.getConnection(function (err, connection) {
              expect(err).to.be.null;
              })
          );
      })
  });
  </code></pre>
  
  <p>Which  would return, if credentials are correct:</p>
  
  <pre><code>Express server listening on port 8080
    Database
      Connection
        - Should connect without an error
  
  
    0 passing (15ms)
    1 pending
  </code></pre>
  
  <p>And return, if credentials are incorrect:</p>
  
  <pre><code>Express server listening on port 8080
    Database
      Connection
        - Should connect without an error
        1) Uncaught error outside test suite
  
  
    0 passing (23ms)
    1 pending
    1 failing
  
    1) Database Connection Uncaught error outside test suite:
       Uncaught AssertionError: expected [Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'userName'@'localhost' to database 'userDatabase'] to be null
  </code></pre>
  
  <p>Thank you in advance.</p>