0

I'm having trouble getting an async event emitter test running in mocha v5.0.4. I'm using a typed Rx based event emitter and node.js v8.10. Can anyone point me in the right direction please?

The first and the second it-blocks work fine. However, the third it-block is never invoked. Mocha doesn't give me a test result (no output at all, mocha runs into the timeout which I set to 10 minutes)

describe('xyz', () => {
  const xyz : Xyz = new Xyz(config);

  describe('make()', () => {

    let emitter : Emitter<Status>;
    emitter = xyz.make("abc", 0.01);

    it('should return an Emitter', () => {
      expect(emitter).to.be.a('Object');
    });

    it('should eventually return a foo', (done) => {
      emitter.on('foo').subscribe( foo => {
        expect(foo).to.be.a('foo');
        done();
      })
    });

    it('should eventually return a bar', (done) => {
      emitter.on('bar').subscribe( bar => {
          console.log('foobar!');
          expect(bar).to.be.a('bar');
          done();
      });
    });

  });
});

What strikes me most is that the event is definitely fired. I can see foobar! as the console output. I'm not using Spies but sticking to the second example from the mocha documents.

hurb
  • 2,177
  • 3
  • 18
  • 32
  • 1
    A couple of questions. 1, Is the subscribe method returning a promise" 2. Is there any error returned by the mocha test? Like Unhandled promise rejection or is the value 'foo' being returned? – user2347763 Mar 28 '18 at 19:41
  • The subscribe method is returning an Observable. No error. `foobar!` is the last thing that is logged. So, the function inside subscribe is executed but the test is never run. – hurb Mar 28 '18 at 20:12
  • 1
    Is emitter typeof status? Have you checked if the make() method returned the typeof because even though emitter might be an object, it still needs to be typeof status for the subscribe to be called correctly? The test is most probably timing out because the event is most probably not getting triggered completely. – user2347763 Mar 28 '18 at 21:34
  • Emitter is an `Emitter` object, the structure of which is `Emitter { emitterState: { observables: `. I think the event is triggered since I see the output of `console.log('foobar!');`. – hurb Mar 28 '18 at 21:49

0 Answers0