title: How to mock npm module with sinon/mocha
body: <p>I'm trying to test a function that calls the module <code>cors</code>. I want to test that <code>cors</code> would be called. For that, I'd have to stub/mock it. </p>
  
  <p>Here is the function 
  cors.js</p>
  
  <pre><code>const cors = require("cors");
  
  const setCors = () =&gt; cors({origin: 'http//localhost:3000'});
  module.exports = { setCors }
  </code></pre>
  
  <p>My idea of testing such function would be something like</p>
  
  <p>cors.test.js</p>
  
  <pre><code>  describe("setCors", () =&gt; {
      it("should call cors", () =&gt; {
        sinon.stub(cors)
  
        setCors();
        expect(cors).to.have.been.calledOnce;
  
      });
    });
  </code></pre>
  
  <p>Any idea how to stub npm module?</p>