title: How to use async mocha before() initialization without setTimeout?
body: <p>I am using Mocha to test out some database queries I created. I need my before <code>block</code> to create the appropriate foreign keys so the unit tests can focus on testing out the raw create/delete functionality of my Node ORM. </p>
  
  <p>My problem is that I am inserting db entries in my <code>before</code> block and the unit tests are running before the <code>before</code> block is finished executing. </p>
  
  <p><a href="https://lostechies.com/derickbailey/2012/08/17/asynchronous-unit-tests-with-mocha-promises-and-winjs/" rel="nofollow">I read that promises should be used to deal</a> with this kind of thing, so I refactored my codebase to use promises but I still can't get around the fact that I need a setTimeout.</p>
  
  <p>How can I perform async <code>before</code> block without needing to wrap my first <code>it</code> block in a <code>setTimeout</code>?</p>
  
  <pre><code>var chai = require('chai');
  var expect = chai.expect;
  var db = require('../server/db/config');
  var models = require('../server/db/models');
  
  describe('scoring', function() {
  
    var testMessage = {
      x: 37.783599,
      y: -122.408974,
      z: 69,
      message: 'Brooks was here'
    };
  
    var messageId = 1;
  
    before(function() {
      var token = '' + Math.random();
      models.createUser(token).then(function() {
        testMessage.userToken = token;
        models.insert(testMessage)
      });
    });
  
    it('should have votes created in db when createVote is called', function(done) {
      setTimeout(function(done) {
        models.createVote(messageId, token, function(err, res) {
          expect(res.insertId).to.be.a('number');
          done();
        });
      }.bind(this, done), 1000);
    });
  });
  </code></pre>