docs.. mock responses API example

This commit is contained in:
Lloyd Brookes
2015-11-27 21:54:33 +00:00
parent 6c4a9a2436
commit 383d48473c
5 changed files with 46 additions and 6 deletions

View File

@ -101,12 +101,14 @@ function mockResponses (route, targets) {
}
if (target) {
debug('target response: %j', target.response)
debug('target response: %s', target.response)
if (t.isFunction(target.response)) {
const pathMatches = ctx.url.match(pathRe).slice(1)
target.response.apply(null, [ctx].concat(pathMatches))
} else {
} else if (t.isPlainObject(target.response)) {
Object.assign(ctx.response, target.response)
} else {
throw new Error(`Invalid response: ${JSON.stringify(target.response)}`)
}
}