Created
February 21, 2014 03:09
-
-
Save joefiorini/9128085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ember.Test.registerHelper('httpRespond', function(app, verb, url, body, status) { | |
function tryResponding() { | |
console.log("matching against url: ", url); | |
var found = fakehr.match(verb.toUpperCase(), url) | |
if (found) { | |
Ember.run(function() { | |
found.respond(status || 200, {'content-type': 'application/json'}, body); | |
}); | |
} | |
return found; | |
} | |
if(typeof body !== 'string'){ body = JSON.stringify(body); } | |
if(!tryResponding()) { | |
fakehr.requestStarted(function(xhr) { | |
var success = tryResponding(); | |
if (!success) { | |
throw new Ember.Error("No request intercepted for " + verb.toUpperCase() + " " + url + ". Intercepted requests were: " + fakehr.requests.map(function(r){ return r.method + " " + r.url}).join(", ")); | |
} | |
}); | |
} | |
}); | |
/* | |
This is mildly crazy. Ember.Test increments requets on ajax start | |
so promises won't resolve until all xhrs complete, but were mocking | |
them all, so we just remove the ajaxStart and ajaxStop callbacks | |
until we can merge into master and put some of this behind flags. | |
*/ | |
Ember.Test.onInjectHelpers(function() { | |
Ember.$(document).unbind("ajaxStart ajaxStop"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment