Skip to content

Commit

Permalink
Merge pull request #174 from 5app/pass-dareinstance-to-handler-in-param
Browse files Browse the repository at this point in the history
feat(handlers): pass dare instance in second parameters
  • Loading branch information
MrSwitch committed Apr 8, 2021
2 parents 280b15e + ba0ef40 commit e22db59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/format_request.js
Expand Up @@ -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);

}

Expand Down
30 changes: 30 additions & 0 deletions test/specs/format_request.js
Expand Up @@ -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);

});

});

});

0 comments on commit e22db59

Please sign in to comment.