jasmine-ajax
jasmine-ajax copied to clipboard
Ability to pass-through requests
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?
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.
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.
:+1: would need this
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.
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.
Closing due to sustained lack of user interest.