diff --git a/lib/core/Axios.js b/lib/core/Axios.js index a1be08adae..d7ce7db415 100644 --- a/lib/core/Axios.js +++ b/lib/core/Axios.js @@ -36,6 +36,10 @@ Axios.prototype.request = function request(configOrUrl, config) { config = configOrUrl || {}; } + if (!config.url) { + throw new Error('Provided config url is not valid'); + } + config = mergeConfig(this.defaults, config); // Set config.method @@ -118,6 +122,9 @@ Axios.prototype.request = function request(configOrUrl, config) { }; Axios.prototype.getUri = function getUri(config) { + if (!config.url) { + throw new Error('Provided config url is not valid'); + } config = mergeConfig(this.defaults, config); return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, ''); }; diff --git a/test/specs/api.spec.js b/test/specs/api.spec.js index eaeadfa2d7..8d81036516 100644 --- a/test/specs/api.spec.js +++ b/test/specs/api.spec.js @@ -11,7 +11,7 @@ describe('static api', function () { }); it('should have promise method helpers', function () { - var promise = axios(); + var promise = axios('/test'); expect(typeof promise.then).toEqual('function'); expect(typeof promise.catch).toEqual('function'); diff --git a/test/specs/requests.spec.js b/test/specs/requests.spec.js index a5aa81aab4..e363fefb0a 100644 --- a/test/specs/requests.spec.js +++ b/test/specs/requests.spec.js @@ -7,6 +7,24 @@ describe('requests', function () { jasmine.Ajax.uninstall(); }); + it('should throw error when missing url', function (done) { + expect(() => axios()).toThrowError(/Provided config url is not valid/); + done(); + + expect(() => axios('')).toThrowError(/Provided config url is not valid/); + done(); + + expect(() => axios({ + url: undefined, + })).toThrowError(/Provided config url is not valid/); + done(); + + expect(() => axios({ + method: 'POST', + })).toThrowError(/Provided config url is not valid/); + done(); + }); + it('should treat single string arg as url', function (done) { axios('/foo');