So the docs are a little thin on the use case of manual async handlers (manual delay in the docs). I'm looking for an easier way to resolve all the manual requests that are sitting around waiting.
// register the handler as manually being resolved
pretender.get('/api/songs', songHandler, true);
fetch('/api/songs');
// then to resolve it, we need a reference to the request
pretender.resolve(request);
Right now I'm using this util function I wrote to do it:
function resolveManualRequests(pretender) {
pretender.requestReferences.forEach((r) => {
if (pretender.requiresManualResolution(r.request.method, r.request.url)) {
pretender.resolve(r.request);
}
});
}
pulling a reference to the request itself to pass in can be a pain. It'd be great to be able to just manually resolve all standing requests. I think just calling pretender.resolve() with no arguments would be a clear way to achieve this. It'd be very easy to implement by just using this.requiresManualResolution(verb, path) and then recursing on itself with the request.
resolve: function resolve(request) {
if (request) {
for (let i = 0, len = this.requestReferences.length; i < len; i++) {
let res = this.requestReferences[i];
if (res.request === request) {
res.callback();
this.requestReferences.splice(i, 1);
break;
}
}
} else {
this.requestReferences.forEach((request) => {
if (this.requiresManualResolution(request.method, request.url)) {
this.resolve(request);
}
});
}
},
So the docs are a little thin on the use case of manual async handlers (manual delay in the docs). I'm looking for an easier way to resolve all the manual requests that are sitting around waiting.
Right now I'm using this util function I wrote to do it:
pulling a reference to the request itself to pass in can be a pain. It'd be great to be able to just manually resolve all standing requests. I think just calling pretender.resolve() with no arguments would be a clear way to achieve this. It'd be very easy to implement by just using this.requiresManualResolution(verb, path) and then recursing on itself with the request.