A / superagent-mocker

Pretty simple in-browser mocks for CRUD and REST API
132 stars 32 forks source link

Middlewares are not firing end/response triggers #22

Closed DKunin closed 7 years ago

DKunin commented 8 years ago

If I attach a middleware to mocked superagent - whether I try to substitute an end callback, or have a trigger on 'end', 'response' events - nothing works. As soon as I unmock - everything works great.

MiddleWare example:

    var middlewareSuperagent = function(req) {
      console.log('STARTED');
      req._callback_orig = req.callback;
      req.callback = function(err, res) {  
        console.log('FINISHED');
        req._callback_orig(err, res);
      }
    };
A commented 8 years ago

Good catch! Thank you!

leviwheatcroft commented 8 years ago

Any progress on this ? It's a deal breaker for many use cases.

I had a quick look at the situation, it looks like superagent binds the events from the original response object I did try doing something similar where we patch Request.end() but couldn't get it to work, and couldn't figure out why. Sorry.

DKunin commented 7 years ago

@A Dude, is this still an issue, maybe the issue should be closed?