Weird Emitter behaviour in specs


#1

So I’m back again with yet another issue testing Jekyll-Atom.

The backbone of Jekyll-Atom is an Emitter which I am faking/tapping into in my specs. The issue I’m having is that the emitter seems to be firing a load more times that it should.

I have a test to ensure that messages arrive in the console:

it 'should write messages to the console', ->
      spy = jasmine.createSpy()

      toolbar.console.html('Test...')
      toolbar.emitter.on 'jekyll:console-message', spy

      toolbar.emitter.emit 'jekyll:console-message', 'Successful'

      waitsFor ->
        spy.callCount > 0

      runs ->
        expect(spy.callCount).toBe 1
        expect(toolbar.console.html()).toBe 'Test...Successful'

As I expect spy.callCount is 1 which by my logic means that the console should contain Test...Successful but it actually contains 10 copies of the word successful.

The handler in the toolbar is:

@emitter.on 'jekyll:console-message', (message) ->
  $('#jtconsole').append(message)
  $('#jtconsole').animate({"scrollTop": $('#jtconsole')[0].scrollHeight}, "fast")

Its not just that specific test either, I test the starting of a Jekyll server through the emitter and it takes an age seemingly (according to activity monitor) because there are a huge number of ruby processes, way more that I have specs.


#2

Have you called getSubscriptionCount on the emitter to determine if there is more than one handler? Perhaps you’re not cleaning up properly between tests?