title: Unit testing an inner function?
body: <p>I have a function that has inner functions, for my unit test, I only want to test the functionality of the inner function, but when I export the function and call the inner function, <em>npm</em> tests returns an error.</p>
  
  <p>In my <code>main.js</code>:</p>
  
  <pre><code>mainFunction = () =&gt; {
    functionToBeTested = () =&gt; {
      // some code
    }
  }
  
  module.exports = {mainFunction: mainFunction}
  </code></pre>
  
  <p>In my <code>test.js</code></p>
  
  <pre><code>const chai    = require("chai");
  const assert  = require("chai").assert;
  const mainFunction = require("./main");
  
  describe ("test", () =&gt; {
   it("returns results", () =&gt; {
    let result = mainfunction.functionToBeTested(args);
    //equal code
    });
  })
  </code></pre>
  
  <p>But when I run <em>npm</em> test, it says: </p>
  
  <blockquote>
    <p>mainfunction.functionToBeTested is not a function.</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>