-
-
Notifications
You must be signed in to change notification settings - Fork 916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
got.extend()
doesn't merge hooks
#606
Comments
hm, if i pass hook to const got = require('got')
const noop = () => {}
const hooks = {
beforeRequest: [console.log],
}
const client = got.create({
options: {
baseUrl: 'https://google.com',
hooks,
},
})
// not works
client
.get('/')
.then(noop)
.catch(noop)
// works
client
.get('/', { hooks })
.then(noop)
.catch(noop) |
Can you elaborate where's the problem? |
How i can define global hooks? when i replace So my solution is wrong. It just replaces hooks(as described here) https://github.com/sindresorhus/got#gotmergeoptionsparentoptions-newoptions |
What do you mean by "global hooks"? |
Hooks that works for all children of instance. With
'use strict'
const got = require('got')
const noop = () => {}
const hooks = {
beforeRequest: [console.log],
}
const client = got.create({
options: {
baseUrl: 'https://google.com',
hooks,
},
})
// hooks here, OK!
console.log(client.defaults.options.hooks)
// but it not works, hook not called
client
.post('/')
.then(noop)
.catch(noop)
// when i pass directly hooks will be called
client
.post('/', { hooks })
.then(noop)
.catch(noop) |
Confirmed bug: test('hooks are merged on got.extend()', t => {
const hooksA = [() => {}];
const hooksB = [() => {}];
const instanceA = got.create({options: {hooks: {beforeRequest: hooksA}}});
const extended = instanceA.extend({hooks: {beforeRequest: hooksB}});
t.deepEqual(extended.defaults.options.hooks.beforeRequest, hooksA.concat(hooksB));
}); EDIT: fixed the test
|
I am try to get options dict for modifing it later. But looks like hook never been called.
got version: 9.2.1
node version: v10.10.0
The text was updated successfully, but these errors were encountered: