jakerella / jquery-mockjax

The jQuery Mockjax Plugin provides a simple and extremely flexible interface for mocking or simulating ajax requests and responses
Other
2.11k stars 375 forks source link

Support for async/deferred responses #45

Closed andreineculau closed 10 years ago

andreineculau commented 12 years ago

Just what the title says. Right now it's impossible to "resolve" the request at a later stage (don't read timeout).

Shouldn't you return a $.Deferred object instead?

Eg. I want to hook up into an ajax call and perform 3 other ajax calls "invisibly", concatenate the payloads and return one single payload

jdsharp commented 12 years ago

Is this for mocking a response or for use in production such as concatenating 3 services?

fracmak commented 12 years ago

I'm also running into the bug. I use deferred objects heavily in my web app and for unit testing it I need the mock ajax requests to return a deferred object that will resolve() when the request is complete (or reject() if they're set up to fail). Right now the ajax requests look like they never complete because I don't use the older callback model

fracmak commented 12 years ago

Actually, I solved the problem. Had included sinon-qunit which activated fake timers. So the mockjax setTimeout was never getting called. :-P

vojtech-dobes commented 11 years ago

Is there planned any progress on this?

Btw @fracmak, how exactly did you solve it :)?

fracmak commented 11 years ago

it was a conflict between sinon and mockjax. Sinon had taken over setTimeout and prevented them from running except after certain calls, which prevented mockjax from completing. Once I figured that out async/promises worked just fine

jakerella commented 10 years ago

I don't believe this is an issue with mockjax any longer. The library actually calls the underlying jQuery ajax() method but simply passes in a fake xhr implementation. It then returns whatever is returned by jQuery's ajax() method. In fact, there are specific tests for deferred objects.

Unless there are other concerns I'm going to close this one for now.