title: Spy module.exports functions with sinon in NodeJS always returning 0
body: <p>I am trying to track the number of calls to another function using a test case written with Sinon. I have the following code, and on running the test, the <code>calledFuncSpy</code> callCount always gets me 0, which is not expected. Meanwhile, running another spy on <code>console.log</code> gives me the correct output, and I have left it commented in the code. Does anyone know what could be the problem?</p>
  <p>Here’s the code. Let me know if more information is required to solve this problem.</p>
  <p><strong>specs/mymodule.js</strong></p>
  <pre><code>const mymodule = require(&quot;../src/mymodule.js&quot;);
  var sinon = require(&quot;sinon&quot;);
  const assert = require(&quot;assert&quot;);
  
  
  
  describe(&quot;Test suite&quot;, function() {
    let calledFuncSpy;
    let consoleSpy;
  
    beforeEach(function () {
      calledFuncSpy = sinon.spy(mymodule, &quot;calledFunc&quot;);
      consoleSpy = sinon.spy(console, &quot;log&quot;);
    })
    afterEach(function () {
      calledFuncSpy.restore();
      consoleSpy.restore();
    })
  
    it(&quot;Test the add method&quot;, function () {
      mymodule.ownHelloWorld();
      assert.deepStrictEqual(calledFuncSpy.callCount, 1);
      // assert.deepStrictEqual(consoleSpy.callCount, 1);
    });
  })
  </code></pre>
  <p><strong>src/mymodule.js</strong></p>
  <pre><code>function ownHelloWorld() {
    calledFunc();
  }
  
  function calledFunc() {
    console.log(&quot;Hello world&quot;);
  }
  
  module.exports = {
    ownHelloWorld,
    calledFunc
  }
  </code></pre>