node.js - How to unit test express route that calls helper function from dependency? -


i have following part of login code. have unit tests written authentication.login() response handling need test.

  app.post('/login', function(req, res) {     var username = req.body.username;     var password = req.body.password;      authentication.login(username, password, function(err, result) {       if (err !== null) {         res.setheader('content-type', 'text/plain');         res.setheader('content-length', err.length);         res.end(err);       } else {         req.session.user = result;         var userfilter = ['username'];         result = json.stringify(result, userfilter);         res.setheader('content-type', 'application/json');         res.setheader('content-length', result.length);         res.end(result);;       }     });   }); 

so write tests check response header , body expected be. how deal authentication.login() function? has been tested presume should using mock/spy here? how manage use them replace authentication object? or there no need mocking authentication.login function, fine leave in code dependency?

you don'n need make changes if decided leave refers dependency.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -