Skip to content

Instantly share code, notes, and snippets.

@fgrehm

fgrehm/gist:4017563

Created Nov 5, 2012
Embed
What would you like to do?
AJAX helpers for JS specs
exports = {}
trueAjax = $.ajax
registry = {}
exports.registerSuccess = (url, result) ->
registry[url] = {success: result}
exports.registerFailure = (url, result) ->
registry[url] = {failure: result}
exports.reset = ->
delete registry[url] for url, result of registry
jQuery.ajax = (options) ->
response = registry[options.url]
throw "Unregistered ajax call to #{options.url}" unless response
deferred = jQuery.Deferred()
if response.success
deferred.resolve(response.success)
else
deferred.reject(response.failure)
window.ajaxHelpers = exports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment