title: How to test event emitters in node
body: <p>Lets say I want to write this simple task. But I want to write a test validating that:</p>
  
  <ol>
  <li>This task emits object.</li>
  <li>Object has a property name.</li>
  </ol>
  
  <p>I'm testing with mocha and chai expect.</p>
  
  <p>Thanks in advance. I've tried every possible variant that came to mind, but could not come up with a solution.</p>
  
  <pre><code>var util = require('util'),
      EventEmitter = require('events').EventEmitter;
  
  function SomeTask() {
    var self = this;
  
    setInterval(function() {
      self.emit('data', { name: 'name' });
    }, 5000);
  }
  
  util.inherits(SomeTask, EventEmitter);
  
  module.exports = SomeTask;
  </code></pre>