From 95f0f00c778ea503b94dd07c2eec91f2b5b5bb43 Mon Sep 17 00:00:00 2001 From: mzabriskie Date: Mon, 28 Sep 2015 18:40:20 -0600 Subject: [PATCH] Fixing axios to treat single string argument as URL closes #116 --- lib/axios.js | 7 +++++++ test/specs/requests.spec.js | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/axios.js b/lib/axios.js index ca9ba15..479be82 100644 --- a/lib/axios.js +++ b/lib/axios.js @@ -6,6 +6,13 @@ var dispatchRequest = require('./core/dispatchRequest'); var InterceptorManager = require('./core/InterceptorManager'); var axios = module.exports = function (config) { + // Allow for axios('example/url') + if (typeof config === 'string') { + config = { + url: config + }; + } + config = utils.merge({ method: 'get', headers: {}, diff --git a/test/specs/requests.spec.js b/test/specs/requests.spec.js index 3833b63..4edc4b2 100644 --- a/test/specs/requests.spec.js +++ b/test/specs/requests.spec.js @@ -9,6 +9,19 @@ describe('requests', function () { jasmine.Ajax.uninstall(); }); + it('should treat single string arg as url', function (done) { + var request; + + axios('/foo'); + + setTimeout(function () { + request = jasmine.Ajax.requests.mostRecent(); + + expect(request.url).toBe('/foo'); + done(); + }, 0); + }); + it('should make an http request', function (done) { var request;