title: how to mock configurable middleware in node js with sinon and mocha
body: <p>I have configurable middleware where I can pass parameters and based on that it calls next function.</p>
  
  <p>middleware code:</p>
  
  <p>File: my-middleware.js</p>
  
  <pre><code>exports.authUser = function (options) {
    return function (req, res, next) {
      // Implement the middleware function based on the options object
      next()
    }
  }
  
  var mw = require('./my-middleware.js')
  
  app.use(mw.authUser({ option1: '1', option2: '2' }))
  </code></pre>
  
  <p>How to mock the middleware using sinon js? </p>
  
  <p>I have done in this way but, it throwing me "TypeError: next is not a function".</p>
  
  <p>Here is my unit test code:</p>
  
  <pre><code>  it("Should return data by id", (done: any) =&gt; {
  
          sandbox.stub(mw, 'authUser')
              .callsFake((req: any, res: any, next: any) =&gt; { return next(); });
  
          server = require('../../index');
  
          let req = {
              "id": '123'
          }
  
          chai.request(server)
              .post("/user")
              .send(req)
              .end((request, res) =&gt; {
  
                  expect(res.status).to.equal(200);
                  expect(res.body.success).to.equal(true);
  
                  done();
              });
      });
  </code></pre>
  
  <p>Can you help me to mock the configurable middleware? Thanks in advance!!</p>