Skip to content

Commit

Permalink
Don't override hooks when merging arguments
Browse files Browse the repository at this point in the history
Fixes #611
  • Loading branch information
szmarczak committed Sep 13, 2018
1 parent 292f78a commit 3ad3950
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/normalize-arguments.js
Expand Up @@ -55,7 +55,8 @@ const preNormalize = options => {
};

module.exports = (url, options, defaults) => {
options = merge({}, defaults.options, options ? preNormalize(options) : {});
options = merge({}, defaults.options, options || {});
options = preNormalize(options);

if (Reflect.has(options, 'url') || (is.object(url) && Reflect.has(url, 'url'))) {
throw new TypeError('Parameter `url` is not an option. Use got(url, options)');
Expand Down
17 changes: 17 additions & 0 deletions test/create.js
Expand Up @@ -190,3 +190,20 @@ test('ability to pass a custom request method', async t => {

t.true(called);
});

test('hooks aren\'t overriden when merging options', async t => {
let called = false;
const instance = got.extend({
hooks: {
beforeRequest: [
() => {
called = true;
}
]
}
});

await instance(s.url, {});

t.true(called);
});

0 comments on commit 3ad3950

Please sign in to comment.