Skip to content

Commit 40cde9d

Browse files
committed
Add tests for axios clients
1 parent 4946569 commit 40cde9d

33 files changed

+435
-0
lines changed

test/fixtures/available-targets.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
"title": "Unirest",
4949
"link": "http://unirest.io/nodejs.html",
5050
"description": "Lightweight HTTP Request Client Library"
51+
},
52+
{
53+
"key": "axios",
54+
"title": "Axios",
55+
"link": "https://github.com/axios/axios",
56+
"description": "Promise based HTTP client for the browser and node.js"
5157
}
5258
]
5359
},
@@ -74,6 +80,12 @@
7480
"title": "XMLHttpRequest",
7581
"link": "https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest",
7682
"description": "W3C Standard API that provides scripted client functionality"
83+
},
84+
{
85+
"key": "axios",
86+
"title": "Axios",
87+
"link": "https://github.com/axios/axios",
88+
"description": "Promise based HTTP client for the browser and node.js"
7789
}
7890
]
7991
},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import axios from "axios";
2+
3+
const options = {
4+
method: 'POST',
5+
url: 'http://mockbin.com/har',
6+
headers: {'content-type': 'application/x-www-form-urlencoded'},
7+
data: {foo: 'bar', hello: 'world'}
8+
};
9+
10+
axios.request(options).then(function (response) {
11+
console.log(response.data);
12+
}).catch(function (error) {
13+
console.error(error);
14+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import axios from "axios";
2+
3+
const options = {
4+
method: 'POST',
5+
url: 'http://mockbin.com/har',
6+
headers: {'content-type': 'application/json'},
7+
data: {
8+
number: 1,
9+
string: 'f"oo',
10+
arr: [1, 2, 3],
11+
nested: {a: 'b'},
12+
arr_mix: [1, 'a', {arr_mix_nested: {}}],
13+
boolean: false
14+
}
15+
};
16+
17+
axios.request(options).then(function (response) {
18+
console.log(response.data);
19+
}).catch(function (error) {
20+
console.error(error);
21+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import axios from "axios";
2+
3+
const options = {
4+
method: 'POST',
5+
url: 'http://mockbin.com/har',
6+
headers: {cookie: 'foo=bar; bar=baz'}
7+
};
8+
9+
axios.request(options).then(function (response) {
10+
console.log(response.data);
11+
}).catch(function (error) {
12+
console.error(error);
13+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import axios from "axios";
2+
3+
const options = {method: 'PROPFIND', url: 'http://mockbin.com/har'};
4+
5+
axios.request(options).then(function (response) {
6+
console.log(response.data);
7+
}).catch(function (error) {
8+
console.error(error);
9+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import axios from "axios";
2+
3+
const options = {
4+
method: 'POST',
5+
url: 'http://mockbin.com/har',
6+
params: {foo: ['bar', 'baz'], baz: 'abc', key: 'value'},
7+
headers: {
8+
cookie: 'foo=bar; bar=baz',
9+
accept: 'application/json',
10+
'content-type': 'application/x-www-form-urlencoded'
11+
},
12+
data: {foo: 'bar'}
13+
};
14+
15+
axios.request(options).then(function (response) {
16+
console.log(response.data);
17+
}).catch(function (error) {
18+
console.error(error);
19+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import axios from "axios";
2+
3+
const options = {
4+
method: 'GET',
5+
url: 'http://mockbin.com/har',
6+
headers: {accept: 'application/json', 'x-foo': 'Bar'}
7+
};
8+
9+
axios.request(options).then(function (response) {
10+
console.log(response.data);
11+
}).catch(function (error) {
12+
console.error(error);
13+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import axios from "axios";
2+
3+
const options = {method: 'GET', url: 'https://mockbin.com/har'};
4+
5+
axios.request(options).then(function (response) {
6+
console.log(response.data);
7+
}).catch(function (error) {
8+
console.error(error);
9+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import axios from "axios";
2+
3+
const options = {
4+
method: 'POST',
5+
url: 'http://mockbin.com/har',
6+
headers: {'content-type': 'application/json'},
7+
data: {foo: 'bar'}
8+
};
9+
10+
axios.request(options).then(function (response) {
11+
console.log(response.data);
12+
}).catch(function (error) {
13+
console.error(error);
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import axios from "axios";
2+
3+
const options = {
4+
method: 'POST',
5+
url: 'http://mockbin.com/har',
6+
headers: {'content-type': 'application/json'},
7+
data: {foo: null}
8+
};
9+
10+
axios.request(options).then(function (response) {
11+
console.log(response.data);
12+
}).catch(function (error) {
13+
console.error(error);
14+
});

0 commit comments

Comments
 (0)