title: Sinon.js and testing with events and new
body: <p>i'm trying to mock a node.js application, but it doesn't work as expected.</p>
  
  <p>I have a node.js Module called GpioPlugin with following method:</p>
  
  <pre><code>function listenEvents(eventId, opts) {
     if(!opts.pin) {
        throw new Error("option 'pin' is missing");
     }
     var listenPort = new onOff(opts.pin, 'in', 'both', {persistentWatch: true});
  
     listenPort.watch(function(err, value) {
        process.emit(eventId+'', value);
     });
  }
  if(typeof exports !== 'undefined') {
      exports.listenEvents = listenEvents;
  }
  </code></pre>
  
  <p>and now i want to write a test using sinon for this method, but i don't know how... What would be the best way to test this?</p>
  
  <p>This tree parts would be fine, if they get tested:
  Error (no problem)
  generation of onOff (how?)
  event with correct params</p>