title: Intercept EventEmitters with Jasmine
body: <p>I'm building a node.js module and I wish also to test it with Jasmine.</p>
  
  <p>Let say my module look similar to this:</p>
  
  <pre><code>var myModule = function (foo, bar) {
  
    // Begin a workflow
    var workflow = new (require('events').EventEmitter)();
  
    workflow.on('test', function () {
      var greet = greet();
      return greet;
    });
  
    workflow.emit('test');
  
  };
  
  function greet () {
    return "Hi!";
  }
  
  module.exports = {
    myModule: myModule
  };
  </code></pre>
  
  <p>How can I test my module with Jasmine targeting all my Events I emit?</p>
  
  <p>Something like this:</p>
  
  <pre><code>var myModule = require('../myModule.js');    
  
  describe('My Module test', function () {
  
    it('should get greet value', function () {
      myModule.on('test', function () { // "test" as I wrote in myModule
        expect(myModule.greet).toHaveBeenCalled();
      });
    });
  });
  </code></pre>