0

I have this middleware function, written with composable-middleware package.

var compose = require('composable-middleware');

module.exports.isAuthenticated = function () {
  return compose()
    .use(function (req, res, next) {
        var authToken = req.get('x-auth-token');
        if (!authToken) {
            return res.sendStatus(401);
        }
        next();
    });
};

I try stub it with Sinon.js. If it was like this

module.exports.isAuthenticated = function (req, res, next) {
    var authToken = req.get('x-auth-token');
    if (!authToken) {
        return res.sendStatus(401);
    }
    next();
};

I would have done

sinon.stub(auth, 'isAuthenticated').callsArg(2);

but the problem is that my function uses composable-middleware and I don't know how to stub it.

GarryOne
  • 1,430
  • 17
  • 21

1 Answers1

1

Actually, the solution was pretty simple.

var compose = require('composable-middleware');

sinon.stub(auth, 'isAuthenticated', function() {
    return compose()
      .use(function (req, res, next) {
        next();
      });
  });
GarryOne
  • 1,430
  • 17
  • 21