Skip to content

Commit

Permalink
Fix non-enumerable options [such as body] not being used
Browse files Browse the repository at this point in the history
Fixes #1342
  • Loading branch information
szmarczak committed Jul 4, 2020
1 parent 4dbada9 commit 8f775c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const nonEnumerableProperties: NonEnumerableProperty[] = [
'form'
];

const setNonEnumerableProperties = (sources: Array<Options | Defaults | undefined>, to: Options): void => {
export const setNonEnumerableProperties = (sources: Array<Options | Defaults | undefined>, to: Options): void => {
// Non enumerable properties shall not be merged
const properties: Partial<{[Key in NonEnumerableProperty]: any}> = {};

Expand Down
8 changes: 6 additions & 2 deletions source/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
StreamOptions
} from './types';
import createRejection from './as-promise/create-rejection';
import Request, {kIsNormalizedAlready} from './core';
import Request, {kIsNormalizedAlready, setNonEnumerableProperties} from './core';
import deepFreeze from './utils/deep-freeze';

const errors = {
Expand Down Expand Up @@ -120,12 +120,16 @@ const create = (defaults: InstanceDefaults): Got => {
) as GotReturn;
};

// TODO: remove this in Got 12
if (is.plainObject(url)) {
options = {
const mergedOptions = {
...url as Options,
...options
};

setNonEnumerableProperties([url, options], mergedOptions);

options = mergedOptions;
url = undefined as any;
}

Expand Down
2 changes: 1 addition & 1 deletion test/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ test('`hooks` are not duplicated', withServer, async (t, server, got) => {
t.deepEqual(result, [1, 2, 3]);
});

test.failing('allowGetBody sends correct json payload with .paginate()', withServer, async (t, server, got) => {
test('allowGetBody sends correct json payload with .paginate()', withServer, async (t, server, got) => {
let page = 1;
server.get('/', async (request, response) => {
const payload = await getStream(request);
Expand Down

0 comments on commit 8f775c7

Please sign in to comment.