Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 'geturi' method for more information #2555

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/core/Axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var buildURL = require('../helpers/buildURL');
var InterceptorManager = require('./InterceptorManager');
var dispatchRequest = require('./dispatchRequest');
var mergeConfig = require('./mergeConfig');
var buildFullPath = require('./buildFullPath');

/**
* Create a new instance of Axios
Expand Down Expand Up @@ -66,7 +67,8 @@ Axios.prototype.request = function request(config) {

Axios.prototype.getUri = function getUri(config) {
config = mergeConfig(this.defaults, config);
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
var transferUrl = buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
return buildFullPath(config.baseURL, transferUrl);
};

// Provide aliases for supported request methods
Expand Down
4 changes: 4 additions & 0 deletions test/specs/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ describe('static api', function () {
expect(typeof axios.CancelToken).toEqual('function');
expect(typeof axios.isCancel).toEqual('function');
});

it('should have getUri method', function() {
expect(typeof axios.getUri).toEqual('function');
});
});

describe('instance api', function () {
Expand Down
27 changes: 27 additions & 0 deletions test/specs/instance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('instance', function () {
'isCancel',
'all',
'spread',
'getUri',
'default'].indexOf(prop) > -1) {
continue;
}
Expand Down Expand Up @@ -110,4 +111,30 @@ describe('instance', function () {
}, 100);
});
});

it('should have getUri on the instance', function() {
var instance = axios.create({
baseURL: 'https://api.example.com'
});
var options = {
url: 'foo/bar',
params: {
name: 'axios'
}
};
expect(instance.getUri(options)).toBe('https://api.example.com/foo/bar?name=axios');
});

it('should correct discard url hash mark', function () {
var instance = axios.create();
var options = {
baseURL: 'https://api.example.com',
url: 'foo/bar?foo=bar#hash',
params: {
name: 'axios'
}
};
expect(instance.getUri(options)).toBe('https://api.example.com/foo/bar?foo=bar&name=axios');
});

});