I have the following as part of my login code. I already have unit tests written for the authentication.login() so its just the response handling itself I need to 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 I will write tests that check the response header and body are what they are expected to be. But how do I deal with the authentication.login() function? It has already been tested so I presume I should be using a mock/spy here? But how would I manage to use them so that they replace the authentication object? Or is there no need for mocking the authentication.login function, is it fine to leave it in the code as a dependency?
You don'n need to make changes if you decided to leave it refers to the dependency.