I’ve run into a problem with Ajax lately. I’m working on a frontend of a large application and at some point it calls a service which is being developed by another team. They have some hard performance issues and while they are doing they best t o keep it stable sometimes AJAX call times out or returns an error.
Meanwhile as I work on client-side I need to mock this service somehow. I could have just replace callback function with a modified version with some fake data I wonder if there are any more elegant ways to solve this problem.
I’d like to be able to the following:
- Completely stub the call to external service;
- Conditionally mock it: if it returns normally I prefer using the actual data, otherwise fake data is fine.
- Automatically actualize fake data: when a server call returns normally save the data behind the scenes so that it can be used for further executions in case of an error.
- Having an ability to pre-process the data coming to a server before it gets into a callback would also be quite nice.
I can certainly write something like that myself but I’m pretty sure that someone solved this problem already.
I’m using jQuery for AJAX calls so a jQuery-specific solution would work just fine, too.
MockAjax might be useful for you, take a look at:
Mock Your Ajax Requests with Mockjax for Rapid Development