     it 'sends object as response', (done) ->
       handler = (request, callback) -> callback(data: text, mimeType: 'text/html')
       protocol.registerStringProtocol protocolName, handler, (error) ->
+        return done(error) if error
         $.ajax
           url: "#{protocolName}://fake-host"
           success: (data, statux, request) ->

    it 'sends object as response', (done) ->
      handler = (request, callback) -> callback(data: buffer, mimeType: 'text/html')
      protocol.registerBufferProtocol protocolName, handler, (error) ->
        $.ajax
          url: "#{protocolName}://fake-host"
          success: (data, statux, request) ->


    it 'sends error when callback is called with nothing', (done) ->
      protocol.registerBufferProtocol protocolName, emptyHandler, (error) ->
        return done(error) if error
        $.ajax
          url: "#{protocolName}://fake-host"
          success: (data) ->
