From ba0ef40f1c297ceadc7da416a63d14be8cde6809 Mon Sep 17 00:00:00 2001 From: Andrew Dodson Date: Thu, 8 Apr 2021 22:35:14 +0100 Subject: [PATCH] feat(handlers): pass dare instance in second parameters --- src/format_request.js | 2 +- test/specs/format_request.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/format_request.js b/src/format_request.js index 18635ef7..1731265e 100644 --- a/src/format_request.js +++ b/src/format_request.js @@ -78,7 +78,7 @@ async function format_request(options = {}, dareInstance) { if (handler) { // Trigger the handler which alters the options... - await handler.call(dareInstance, options); + await handler.call(dareInstance, options, dareInstance); } diff --git a/test/specs/format_request.js b/test/specs/format_request.js index 08309391..c06733ce 100644 --- a/test/specs/format_request.js +++ b/test/specs/format_request.js @@ -1109,6 +1109,36 @@ describe('format_request', () => { }); + it('should provide the instance of dare in the request', () => { + + let dareInstance; + let that; + + dare.options = { + get: { + users(options, _dareInstance) { + + dareInstance = _dareInstance; + that = this; + + } + }, + method: 'get' + }; + + dare.format_request({ + method, + table: 'users', + fields: [ + 'name' + ] + }); + + expect(dareInstance).to.equal(dare); + expect(that).to.equal(dare); + + }); + }); });