title: Unit Testing Controllers use Jest, NodeJS
body: <p>I want to check a case that certain routes are calling the correct controller use <strong>Jest</strong> specific <em>(mock or spy)</em>.</p>
  
  <p>It is case specific for unit testing. Somebody can help me how to check it use jest. I don't need verify kind of 
  expect (status code or res object) i need to check if <strong>controller</strong> have been called.
  Thanks!</p>
  
  <p>For instance:</p>
  
  <pre><code>// todoController.js
  function todoController (req, res) {
      res.send('Hello i am todo controller')
  } 
  
  // index.spec.js
  const express = require('express');
  const request = require('request-promise');
  const todoController = require('./todoController');
  jest.mock('./todoController');
  
  const app = express();
  
  app.get('/todo', todoController)
  
  test('If certain routes are calling the correct controller , controller should to have been called times one.', async() =&gt; {
      await request({url: 'http://127.0.0.1/todo'})
      expect(todoController).toHaveBeenCalledTimes(1);
  })
  </code></pre>