jasmine-ajax icon indicating copy to clipboard operation
jasmine-ajax copied to clipboard

Ability to pass-through requests

Open warpech opened this issue 9 years ago • 5 comments

In my test, I need to mock a certain XHR request but pass-though all the other requests. Currently, it is only possible if I run jasmine.Ajax.install() / jasmine.Ajax.uninstall() between requests. But this requires me to change files that make the requests.

It would be much cleaner if I could set up FakeXMLHttpRequest to pass-through requests on a certain condition.

WDYT?

warpech avatar Nov 06 '14 13:11 warpech

The purpose of mocking out ajax requests is to make your specs more predictable, because you're not relying on a server being available to get you the responses you expect. Because of this, we don't currently have any plans to make this kind of functionality available in jasmine-ajax.

I'm not totally averse to this functionality, though, so if you want to spend some time and figure out a good way to accomplish this without breaking any of the exist logic, I'd be happy to review a pull request.

slackersoft avatar Nov 06 '14 16:11 slackersoft

We haven't heard any other feedback from the community on this so I'm going to close this issue. If you have time to put together a pull request that can accomplish this without breaking any of the existing logic, we'd be happy to review it.

Thanks for using jasmine.

slackersoft avatar Jan 20 '15 00:01 slackersoft

:+1: would need this

ximus avatar Aug 18 '15 21:08 ximus

Would need this too. I'm hitting against an issue where using this together with source-map-support breaks, because if there's an exception, source-map-support will try to fetch the source maps of all the files and fail because XMLHttpRequest is mocked. A callback than can decide if the request should be mocked or passed through would address a situation like this.

guncha avatar Jan 07 '16 20:01 guncha

I think the interface that makes sense would be to use the stubRequest syntax, but instead of andReturn something like andMakeRequest to indicate that the real XMLHttpRequest object should be used instead.

I'm not sure what this would really look like though, because with the way the XHR interface works, the code making the request has probably already hooked into the fake XHR and jasmine-ajax would have to proxy everything back from the real XHR object through to its consumers.

We'd be happy to review a pull request that makes this work, but it seems like a bit of an edge case.

slackersoft avatar Feb 17 '16 00:02 slackersoft

Closing due to sustained lack of user interest.

sgravrock avatar Sep 23 '23 17:09 sgravrock