title: Unit testing of private functions with Mocha and Node.js
body: <p>I am using <a href="https://en.wikipedia.org/wiki/Mocha_(JavaScript_framework)" rel="noreferrer">Mocha</a> in order to unit test an application written for Node.js.</p>
  <p>I wonder if it's possible to unit test functions that have not been exported in a module.</p>
  <p><strong>Example:</strong></p>
  <p>I have a lot of functions defined like this in <code>foobar.js</code>:</p>
  <pre><code>function private_foobar1(){
      ...
  }
  
  function private_foobar2(){
      ...
  }
  </code></pre>
  
  <p>And a few functions exported as public:</p>
  <pre><code>exports.public_foobar3 = function(){
      ...
  }
  </code></pre>
  <p>The test case is structured as follows:</p>
  <pre><code>describe(&quot;private_foobar1&quot;, function() {
      it(&quot;should do stuff&quot;, function(done) {
          var stuff = foobar.private_foobar1(filter);
          should(stuff).be.ok;
          should(stuff).....
  </code></pre>
  <p>Obviously this does not work, since <code>private_foobar1</code> is not exported.</p>
  <p>What is the correct way to unit-test private methods? Does Mocha have some built-in methods for doing that?</p>