From 7d407fddc25027958572a2c1bb6d667e06db0db3 Mon Sep 17 00:00:00 2001 From: Lloyd Brookes Date: Tue, 24 Nov 2015 12:47:27 +0000 Subject: [PATCH] Mock fix --- lib/middleware.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 44eadbc..d76c0db 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -101,16 +101,17 @@ function mockResponses (route, targets) { } if (target) { - let mockedResponse = target.response + debug('target response: %j', target.response) if (t.isFunction(target.response)) { const pathMatches = ctx.url.match(pathRe).slice(1) - const ctor = target.response.bind(null, ...[ctx].concat(pathMatches)) - mockedResponse = new ctor() + target.response.apply(null, [ctx].concat(pathMatches)) + } else { + Object.assign(ctx.response, target.response) } - debug('target response: %j', mockedResponse) - Object.assign(ctx.response, mockedResponse) + } + } else { + return next() } - return next() } }