title: How does variable scope work within the Mocha test framework?
body: <p>I am a relative newbie to all things javascript, node.js, mocha etc. </p>
  
  <p>In my code I have a Unit object that has a <code>disable()</code> that sets the disabled property to true and a <code>isDisabled()</code> that returns the disabled property. It also has a method <code>nextTurnReset()</code> that resets the unit on the start of the next turn. I have written a test suite to test this behavior. I first disable the object and then try to test to see if it is disabled. However, the unit variable inside my first test - which is within the anonymous function passed to the Mocha's <code>it()</code> method - is in the the non-disabled state as I observed with node's debugger. </p>
  
  <pre><code>describe('#disable()', function() {
      var unit = tests.newUnit();
      unit.disable();
      debugger;
      it('disabled off turn?', function() {
          debugger;
          (unit.isDisabled()).should.be.exactly(true);
      });
      unit.nextTurnReset();
      it('disabled on next turn?', function() {
          (unit.isDisabled()).should.be.exactly(true);
      });
      unit.nextTurnReset();
      it('disabled on 2nd turn?', function() {
          (unit.isDisabled()).should.be.exactly(false);
      });
  });
  </code></pre>
  
  <p>for the record, the first two tests fail, and the last one succeeds indicating the unit is never disabled at all. </p>
  
  <p>from using the node debugger's repl: After the first <code>debugger;</code> statement, <code>unit.disabled == true</code>, but after the second <code>debugger;</code> statement <code>unit.disabled == false</code>. I expect the value to true in both cases.  </p>
  
  <p>Any idea why this would be the case? Also, what is the correct way of writing Mocha tests to get my expected result?</p>
  
  <p>Thanks so much! </p>