title: How to spy a function with Sinon.js that is in the same js file as the function under test
body: <p>I have a problem with Sinon.js while trying to spy a function that is in the same javascript file as the function that I want to test. Furthermore I assert that the spied function is called once. Unfortunately the test fails. Interesting thing is, that if the spied function is in another javascript file than the function under test it works ! </p>
  
  <p>Here is my code: </p>
  
  <p>mock_test.js:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>   
  var sinon = require('sinon')
  
  var one = require('./one.js')
  var two = require('./two.js')
  
  describe('Spy ', function () {
  
    it('Spy another method', sinon.test(function (done) {
      var another_method_spy = sinon.spy(one, 'another_method')
  
      one.some_method()
      sinon.assert.calledOnce(another_method_spy)
      done()
    }))
  
    it('Spy second method', sinon.test(function (done) {
      var second_method = sinon.spy(two, 'second')
  
      one.call_second()
      sinon.assert.calledOnce(second_method)
      done()
    }))
  
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p>one.js:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var two = require('./two.js')
  
  var some_method = function(){
    console.log('one: some method')
    another_method()
  }
  
  var another_method = function(){
    console.log('one: another method')
  }
  
  var call_second = function(){
    console.log('one: call second')
    two.second()
  }
  
  module.exports.some_method = some_method
  module.exports.another_method = another_method
  module.exports.call_second = call_second</code></pre>
  </div>
  </div>
  </p>
  
  <p>two.js:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var second = function(){
    console.log('two: second')
  }
  
  module.exports.second = second</code></pre>
  </div>
  </div>
  </p>
  
  <p>I couldn't find anything helpful in the internet and also I tried different things. Please help, what am I missing here ?</p>
  
  <p>Cheers 
  Noah</p>