Skip to content

Commit 9deec4c

Browse files
Fixed error when request is called with no options argument (#218)
no issue - `request(url)` was erroring because the function code expects the `options` argument to be an object and throws an error if it's not passed and therefore `undefined` - added default argument value to cover the simplified one-argument call signature
1 parent d798043 commit 9deec4c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/request/lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const defaultOptions = {
1616
method: 'GET'
1717
};
1818

19-
module.exports = async function request(url, options) {
19+
module.exports = async function request(url, options = {}) {
2020
// Initialise ES6 imports
2121
if (!got) {
2222
got = (await gotPromise).default;

packages/request/test/request.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ describe('Request', function () {
1919
});
2020
});
2121

22+
it('can be called with no options', function () {
23+
const url = 'http://some-website.com/endpoint/';
24+
25+
const requestMock = nock('http://some-website.com')
26+
.get('/endpoint/')
27+
.reply(200, 'Response body');
28+
29+
return request(url).then(function () {
30+
requestMock.isDone().should.be.true();
31+
});
32+
});
33+
2234
it('[success] should return response for http request', function () {
2335
const url = 'http://some-website.com/endpoint/';
2436
const expectedResponse = {

0 commit comments

Comments
 (0)