diff --git a/index.js b/index.js index 2514d51..2fd4371 100644 --- a/index.js +++ b/index.js @@ -56,7 +56,7 @@ module.exports = fp( function race (opts = globalOpts) { const { raw, id: reqId } = this const handleError = typeof opts === 'function' ? true : opts.handleOnError - const cb = typeof opts === 'function' ? opts : opts.onRequestClosed + const cb = (typeof opts === 'function' ? opts : opts.onRequestClosed).bind(this) if (controllers.has(this)) { const { controller: ctrl, cbs } = controllers.get(this) diff --git a/test/index.test.js b/test/index.test.js index 4cc2983..fe7d402 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -85,11 +85,11 @@ tap.test('fastify-racing#decoration', subtest => { ) }) -tap.test('fastify-racing#promise', { only: true }, subtest => { +tap.test('fastify-racing#promise', subtest => { subtest.plan(4) subtest.test('Should handle a request aborted', t => { - t.plan(3) + t.plan(2) const app = fastify() // eslint-disable-next-line no-undef @@ -118,11 +118,10 @@ tap.test('fastify-racing#promise', { only: true }, subtest => { { method: 'GET', path: '/', - signal: abtCtlr.signal + signal: abtCtlr.signal, + pipelining: 0, }, - err => { - t.ok(err) - } + () => {} ) // Allow a full event loop cycle