title: Testing MySQL connection in Mocha
body: <p>I'm working at learning mocha and chai.
  Thought I was keeping it simple with a database connection test.</p>
  
  <p>The tests seemed fine at first, but something made me look closer.
  The tests were succeeding, so they should also fail under certain circumstances too right?
  I wanted to see a fail so I forced a scenario</p>
  
  <pre><code>it('db.connection.connect should return a connection object using default config.js credentials ', function(){
      var result = "FAIL!";
      db.connection.connect(function(err, result) {
          if(err){
              console.log("SQL CONNECT ERROR: " + err);
              result=(err);
          } else {
              //console.log("SQL CONNECT SUCCESSFUL.");
              //result = "SQL CONNECT SUCCESSFUL.";
              console.log("Test succeeded but result should show fail");
          }
          expect(result).to.equal("SQL CONNECT SUCCESSFUL.");
      });
  });
  </code></pre>
  
  <p>However, now the test won't succeed. The "result" variable is never altered as expected.</p>
  
  <pre><code>it('db.connection.connect should return a connection object using default config.js credentials ', function(){
      var result = "FAIL!";
      db.connection.connect(function(err, result) {
          if(err){
              console.log("SQL CONNECT ERROR: " + err);
              result=(err);
          } else {
              console.log("SQL CONNECT SUCCESSFUL.");
              result = "SQL CONNECT SUCCESSFUL.";
              //console.log("Test succeeded but result should show fail");
          }
      });
      expect(result).to.equal("SQL CONNECT SUCCESSFUL.");
  });
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/4SjaN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4SjaN.png" alt="enter image description here"></a></p>