forked from trek/ember-testing-httpRespond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpRespond-1.1.js
24 lines (22 loc) · 1.04 KB
/
httpRespond-1.1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Ember.Test.registerAsyncHelper('httpRespond', function(app, verb, url, body, status, requestBody) {
if(typeof body !== 'string'){ body = JSON.stringify(body); }
if(typeof requestBody !== 'string'){ requestBody = JSON.stringify(requestBody); }
var found = fakehr.match(verb.toUpperCase(), url, 1, requestBody);
if (found){
Ember.run(function() {
found.respond(status || 200, {'content-type': 'application/json'}, body);
});
} else {
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(", "));
}
return wait(app);
});
/*
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");
});