title: How to unit test a callback in node.js using sinon, when callback is not passed as parameter?
body: <pre><code>var data = function (req, res, next) {
      var data;
      modelClass.getData(function (err, response) {
              data = response[0];
              req.headers[constants.DATA] = data;
              next();
          }
      });
  };
  </code></pre>
  
  <p>How would I unit test the above function, in Node.js (express.js) especially when callback is not passed in as parameter? I plan to use the Sinon unit test framework.</p>
  
  <p>The examples shown here: <a href="https://www.youtube.com/watch?v=Qlmv7nox5pM" rel="nofollow noreferrer">youtube tutorial</a> only shows how to test when call back is passed as parameter.</p>