Hacker News new | past | comments | ask | show | jobs | submit login
Mocking jQuery AJAX with AmplifyJS Request (elijahmanor.com)
15 points by elijahmanor on Oct 3, 2012 | hide | past | favorite | 4 comments



I assume everyone already knows about mockjax [1], a fantastic library for mocking out plain-old jquery ajax requests. It's a great way to develop and test Backbone apps against an API contract even before the API is up and running.

[1] https://github.com/appendto/jquery-mockjax


Yeah mockjax is a great library as well. I usually recommend people added mockjax to existing projects, but if it is a new project recommend using amplify.request. The amplify.request piece enables you to do some things you can't easily with mockjax. For example, amplify.request allows you to change the caching strategy in the define statements and not where the request is being made. Also if the data from the server changes you can add a decoder to the define statement to map the data to what your code expects. Or if the data going out changes you can add a dataMap to the define statement to so your main application code doesn't have to change. You can also create a custom request type other than jQuery AJAX (think maybe websockets or Dojo's ajax). I sometimes use mockjax also in a jsFiddle or demo code where I don't want to get into amplify.request and just want to use out of the box jQuery.ajax. Thanks for your comment.


Somewhat related is that Elijah showed Aaron Powell this some time ago and he blogged about it at http://aaron-powell.com/javascript/stubbing-ajax-responses-w... but used a different mock objects generator. This technique has come in quite handy, so thanks for showing Aaron this Elijah.


No problem. Aaron Powell is a great guy and a smart dude. Yeah, check out his posts ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: