diff --git a/src/index.js b/src/index.js index 237abf0..d226183 100644 --- a/src/index.js +++ b/src/index.js @@ -12,8 +12,8 @@ const createTestServer = opts => createCert(opts && opts.certificate) const get = app.get.bind(app); const server = http.createServer(app); const sslServer = https.createServer(keys, app); - const send = fn => (req, res) => { - const cb = typeof fn === 'function' ? fn(req, res) : fn; + const send = fn => (req, res, next) => { + const cb = typeof fn === 'function' ? fn(req, res, next) : fn; new Promise(resolve => resolve(cb)).then(val => { if (val) { @@ -48,8 +48,15 @@ const createTestServer = opts => createCert(opts && opts.certificate) }) ]); - app.get = (path, fn) => { - get(path, send(fn)); + app.get = function () { + // TODO: Use destructuring when targeting Node.js v6 + const args = Array.from(arguments); + const path = args[0]; + const fns = args.slice(1); + + for (const fn of fns) { + get(path, send(fn)); + } }; return app.listen().then(() => app); diff --git a/test/create-test-server.js b/test/create-test-server.js index ccd70b5..7b816c3 100644 --- a/test/create-test-server.js +++ b/test/create-test-server.js @@ -121,3 +121,15 @@ test('support returning body directly without wrapping in function', async t => t.deepEqual(bodyJson, { foo: 'bar' }); t.deepEqual(bodyAsync, 'bar'); }); + +test('accepts multiple callbacks in `.get()`', async t => { + const server = await createTestServer(); + + server.get('/foo', (req, res, next) => { + res.set('foo', 'bar'); + next(); + }, (req, res) => res.get('foo')); + + const { body } = await got(server.url + '/foo'); + t.is(body, 'bar'); +});