title: SINON unittesting stub constructor
body: <p>I'm trying to stub a constructor in node but I really can't.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/38847398/node-stub-a-method-that-returns-an-object">this</a> , that is quite similiar to what I need to do but I have an error that I could not solve.</p>
  
  <pre><code>//file.js
  var foo = require('foo-client')
  function toTest () {
       var bar = foo()
      returns config = bar.foo2(a,b)  // returns a Promise
  }
  </code></pre>
  
  <p>what I am trying to do in the test file is </p>
  
  <pre><code>//file-sepc.js
  var stub = sinon.stub()
  stub.returns(Promise.resolve('config'))// config it's just an example
  
      var file = proxyquire('./file.js', {
          'foo-client':{foo2: stub}
      })
  file.toTest()
  .then((result) =&gt; {
       console.log(result)
       done()
  })
  </code></pre>
  
  <p>supposing the node syntax is correct, I am getting this output:</p>
  
  <pre><code> TypeError: foo is not a function
  </code></pre>
  
  <p>Can anyone help me telling me where is my error or another way to mock/stub this things? </p>
  
  <h2>Thanks a lot!</h2>