This commit is contained in:
Lloyd Brookes
2016-02-19 19:28:22 +00:00
parent 8145986987
commit 86a1787540
5 changed files with 11 additions and 9 deletions

View File

@ -78,7 +78,7 @@ function mime (mimeTypes) {
function mockResponses (route, targets) {
targets = arrayify(targets)
debug('mock route: %s, targets: %s', route, targets.length);
debug('mock route: %s, targets: %s', route, targets.length)
const pathRe = pathToRegexp(route)
return function mockResponse (ctx, next) {
@ -103,13 +103,12 @@ function mockResponses (route, targets) {
if (target) {
if (t.isFunction(target.response)) {
const pathMatches = ctx.path.match(pathRe).slice(1)
return target.response.apply(null, [ctx].concat(pathMatches))
return target.response.apply(null, [ctx].concat(pathMatches))
} else if (t.isPlainObject(target.response)) {
Object.assign(ctx.response, target.response)
} else {
throw new Error(`Invalid response: ${JSON.stringify(target.response)}`)
}
}
} else {
return next()