2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-05 16:42:32 +03:00

Adding support for params

This commit is contained in:
Matt Zabriskie
2014-08-27 02:08:39 -06:00
parent 9096d34186
commit 514e281a1b
8 changed files with 703 additions and 228 deletions
+13
View File
@@ -88,6 +88,19 @@ describe('axios', function () {
expect(request.requestHeaders['X-Requested-With']).toEqual('XMLHttpRequest');
});
it('should accept params', function () {
axios({
url: '/foo',
params: {
foo: 123,
bar: 456
}
});
var request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toBe('/foo?foo=123&bar=456');
});
it('should allow overriding default headers', function () {
axios({
headers: {
+67
View File
@@ -0,0 +1,67 @@
var buildUrl = require('../../lib/buildUrl');
module.exports = {
testNullParams: function (test) {
var url = buildUrl('/foo');
test.equals(url, '/foo');
test.done();
},
testParams: function (test) {
var url = buildUrl('/foo', {
foo: 'bar'
});
test.equals(url, '/foo?foo=bar');
test.done();
},
testObjectParam: function (test) {
var url = buildUrl('/foo', {
foo: {
bar: 'baz'
}
});
test.equals(url, '/foo?foo=' + encodeURI('{"bar":"baz"}'));
test.done();
},
testDateParam: function (test) {
var date = new Date();
var url = buildUrl('/foo', {
date: date
});
test.equals(url, '/foo?date=' + date.toISOString());
test.done();
},
testArrayParam: function (test) {
var url = buildUrl('/foo', {
foo: ['bar', 'baz']
});
test.equals(url, '/foo?foo=bar&foo=baz');
test.done();
},
testSpecialChars: function (test) {
var url = buildUrl('/foo', {
foo: '@:$, '
});
test.equals(url, '/foo?foo=@:$,+');
test.done();
},
testQuestionMark: function (test) {
var url = buildUrl('/foo?foo=bar', {
bar: 'baz'
});
test.equals(url, '/foo?foo=bar&bar=baz');
test.done();
}
};