title: Mocha - pass variable to `beforeEach` and `afterEach` from `it`
body: <p>This question could solve a lot of general solutions, so I'll try to phrase it in such a way. I have a situation where I need the same <code>beforeEach</code> and <code>afterEach</code> block of code run but need to alter just one variable (or a couple) each time.</p>
  
  <p>My specific scenario: I need to insert/delete from a database each time. Code:</p>
  
  <p>First setting up temporary table for tests:</p>
  
  <pre><code>before(function(done) {
      db.query('CREATE TEMPORARY TABLE tmp AS SELECT * FROM example_table', null, function(error) {
          return done();
      });
  });
  </code></pre>
  
  <p>Then hooks before/after each test <strong>[EDIT with @luboskrnac suggestions]</strong>:</p>
  
  <pre><code>var vals = []
  
  beforeEach(init_vals, function(done) {
      mysql.query('INSERT INTO tmp (a, b) VALUES (?, ?)', init_vals, function(error, rows) {
          return done();
      });
  });
  
  // pass values [1, 2] to `beforeEach`
  it('check value is in database', function(done) {
      mysql.query('SELECT * FROM tmp WHERE a = ? AND b = ?', function(error, rows) {
          vals = [1, 2];
          expect(rows[0].a === vals.a);
          expect(rows[0].b === vals.b);
          return done(); // pass values
      })
  })
  
  afterEach(function(done) {
      mysql.query('DELETE FROM tmp WHERE a = ? AND b = ?', vals, function(error, rows) {
          return done();
      });
  });
  </code></pre>
  
  <p>Then (temporary) table is cleaned up when session closes. Is there anyway to pass <code>values</code> as a variable to these hooks for each <code>it</code> test?</p>