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?
the function shouldn't be returning next(), it should call next after it's completed its operation. EG:
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");
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.