0

I've got a function which returns next(); as a function to allow next route to be called and it's used for checking the token as an interceptor and allows function to go through.

The problem I have now is that I want to test this particular function and I don't have next route it's just that one so when I use some API testing tool like Hippie and make a request it hangs and does nothing until timed out.

So the test call I have is like below with Hippie:

    hippie(server)
        .header('token', token)
        .json()
        .put('/token')
        .send(tokenRequest)
        .end(function(err, res, body) {
            if (err) {
                throw err;
            }

            done();
        });

Basically token endpoint is linking to token interceptor and that returns next();

How do I make this into testable state?

Esailija
  • 138,174
  • 23
  • 272
  • 326
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168

1 Answers1

0

the function shouldn't be returning next(), it should call next after it's completed its operation. E.G.:

    module.router.post('/*', function(req,res,next){
       middleware.doSomething()
       .then(function(){
          next();
       });
    });

    module.router.post('/user', function(req,res,next){
       //comes here from the next() above
       res.status(501).send("unimplemented");
    });