title: Mock a custom event emitter with jest
body: <p>I want to assert that emit from the EventEmitter class was called with specific parameters by using Jest. I have a separate file where I create an instance of eventEmitter to be used, and on the other class I import it and at some point the event is emitted.</p>
  
  <pre><code>// commonEmitter.ts
  const events = require('events');
  export const commonEmitter = new events.EventEmitter();
  
  // class.ts
  import { commonEmitter } from (..)
  
  export class MyClass {
     (...)       
  
     method(){
       commonEmitter.emit('eventName', { data: true});
     }
  }
  
  // class.spec.ts
  
  let commonEmitterMock: any
  
  beforeEach(() =&gt; {
    commonEmitterMock = createMock('emit');
  });
  
  
  it('testMyClass', async () =&gt; {
     const method = new MyClass().method();
     expect(commonEmitterMock).toHaveBeenCalledWith('eventName', { data: true})
  }
  </code></pre>
  
  <p>With this implementation the emit event is never called.. 
  Cant figure out why, any idea?</p>