title: Can I connect to mongoose from within a test?
body: <p>I'm trying to run a chai test that connects to mongodb using mongoose, but it is failing with 'expected undefined to be an object'. I'm using the same method that I use in the functioning app. Am I connecting to the database correctly? </p>
  
  <pre><code>var expect = require('chai').expect;
  var eeg = require('../eegFunctions');
  var chai = require("chai");
  var chaiAsPromised = require("chai-as-promised");
  chai.use(chaiAsPromised);
  var mongoose = require('mongoose');
  var db = mongoose.connection;
  
  db.on('error', console.error);
  db.once('open', function callback(){console.log('db ready');});
  
  mongoose.connect('mongodb://localhost/eegControl');
  
  test("lastShot() should return an object", function(){
  
      var data;
      eeg.lastShot(function(eegData){
          data = eegData;
      });
      return expect(data).to.eventually.be.an('object');        
  
  });
  </code></pre>