From e83e5399929fc541b67d154e9eee0ec1d24005a0 Mon Sep 17 00:00:00 2001 From: Alex Deas Date: Fri, 5 Apr 2019 11:51:09 +0100 Subject: [PATCH] Persist mutations to res.locals Adds persistence to res.locals by using Object constructor syntax rather than Object literal syntax. This returns an object reference and means that when passed to a function the reference is updated. As this reference is avilable outside the middleware being tested it means that changes to res.locals can be tested. --- src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index a6a81d1..e4a38d6 100644 --- a/src/index.js +++ b/src/index.js @@ -34,7 +34,6 @@ export const mockRes = (options = {}) => { json: sinon.stub().returns(ret), jsonp: sinon.stub().returns(ret), links: sinon.stub().returns(ret), - locals: {}, location: sinon.stub().returns(ret), redirect: sinon.stub().returns(ret), render: sinon.stub().returns(ret), @@ -47,5 +46,7 @@ export const mockRes = (options = {}) => { vary: sinon.stub().returns(ret), write: sinon.stub().returns(ret), writeHead: sinon.stub().returns(ret), - }, options) + }, + options, + { locals: new Object(options.locals || {}) }) }