title: Using node-mocks-http to test a service no event emitted
body: <p>I have a simple service I'd like to test, by calling its controller. I thought I'd use <a href="https://github.com/howardabrams/node-mocks-http" rel="nofollow">node-mocks-http</a> to create a mock request, and look at the results of the response. However, despite all the documentation and sample code, I could not get the response to emit any event ("end", "send" or even "error"), and can't therefore know when to test the output.</p>
  
  <p>Here's a simple function (using Express 4.*):</p>
  
  <pre><code>export function getServiceHealth(req, res) {
    let message = 'service has been up for ' + process.uptime() + ' seconds!';
    res.status(200).send(message);
  }
  </code></pre>
  
  <p>Here's my test (Jasmine):</p>
  
  <pre><code>import {EventEmitter} from 'events';
  import httpMock from 'node-mocks-http';
  import {getServiceHealth} from '../../lib/controllers/health/';
  
  describe('Service health integration tests', () =&gt; {
    it('should get health', done =&gt; {
      let req = httpMock.createRequest({url: '/health'});
      let res = httpMock.createResponse({EventEmitter: EventEmitter});
      getServiceHealth(req, res);
      res.on('end', () =&gt; {
        console.log(res._getData());
        done();
      });
      res.on('send', () =&gt; {
        console.log(res._getData());
        done();
      });
      //setTimeout(() =&gt; {console.log(res._getData()); done();}, 1000);
    });
  });
  </code></pre>
  
  <p>The only way I ever get this test to finish (without throwing a timeout error) is by uncommenting the <code>setTimeout</code> line - obviously not the right way to go. And when I do, the data in <code>res</code> is exactly what I expect it to be - meaning that other than event firing, everything works ok.</p>
  
  <p>What do I have to do to get the event triggered on <code>res</code>?</p>
  
  <p><strong>PS</strong>: on the off chance that this is some ES6 import shenanigan, I tried this:</p>
  
  <pre><code>let res = httpMock.createResponse({EventEmitter: require('events').EventEmitter});
  </code></pre>
  
  <p>Same result.</p>
  
  <p><strong>PPS</strong>: Opened <a href="https://github.com/howardabrams/node-mocks-http/issues/73" rel="nofollow">issue</a> on repo</p>