 
     describe 'when called with an invalid request', ->
       beforeEach (done) ->
+        @eventForwarder.on 'message', (@message) =>
+          done() if @message.topic == 'unregister-error'
+
         @meshblu.unregister uuid: 'invalid-uuid', (error) =>
-          @eventForwarder.once 'message', (@message) =>
-            done()
 
       it 'should send an "unregister-error" message', ->
         expect(@message.topic).to.deep.equal 'unregister-error'


    describe 'when called with an invalid request', ->
      beforeEach (done) ->
        @meshblu.generateAndStoreToken uuid: 'invalid-uuid', (data) =>
          @eventForwarder.once 'message', (@message) =>
            done()

      it 'should send an "generatetoken-error" message', ->
        expect(@message.topic).to.deep.equal 'generatetoken-error'


    describe 'when called with an invalid request', ->
      beforeEach (done) ->
        @eventForwarder.on 'message', (@message) =>
          done() if @message.topic == 'register-error'
        @meshblu.register uuid: 'not-allowed', (error) =>

      it 'should send an "register-error" message', ->
        expect(@message.topic).to.deep.equal 'register-error'
