-
-
Notifications
You must be signed in to change notification settings - Fork 11k
/
Copy pathoptions.spec.js
130 lines (102 loc) · 3.53 KB
/
options.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import AxiosHeaders from "../../lib/core/AxiosHeaders.js";
describe('options', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should default method to get', function (done) {
axios('/foo');
getAjaxRequest().then(function (request) {
expect(request.method).toBe('GET');
done();
});
});
it('should accept headers', function (done) {
axios('/foo', {
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['X-Requested-With']).toEqual('XMLHttpRequest');
done();
});
});
it('should accept params', function (done) {
axios('/foo', {
params: {
foo: 123,
bar: 456
}
});
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo?foo=123&bar=456');
done();
});
});
it('should allow overriding default headers', function (done) {
axios('/foo', {
headers: {
'Accept': 'foo/bar'
}
});
getAjaxRequest().then(function (request) {
expect(request.requestHeaders['Accept']).toEqual('foo/bar');
done();
});
});
it('should accept base URL', function (done) {
const instance = axios.create({
baseURL: 'http://test.com/'
});
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://test.com/foo');
done();
});
});
it('should warn about baseUrl', function (done) {
spyOn(window.console, 'warn');
const instance = axios.create({
baseUrl: 'http://example.com/'
});
instance.get('/foo');
getAjaxRequest().then(function (request) {
expect(window.console.warn).toHaveBeenCalledWith('baseUrl is likely a misspelling of baseURL');
expect(request.url).toBe('/foo');
done();
});
});
it('should ignore base URL if request URL is absolute', function (done) {
const instance = axios.create({
baseURL: 'http://someurl.com/'
});
instance.get('http://someotherurl.com/');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://someotherurl.com/');
done();
});
});
it('should change only the baseURL of the specified instance', function() {
const instance1 = axios.create();
const instance2 = axios.create();
instance1.defaults.baseURL = 'http://instance1.example.com/';
expect(instance2.defaults.baseURL).not.toBe('http://instance1.example.com/');
});
it('should change only the headers of the specified instance', function() {
const instance1 = axios.create();
const instance2 = axios.create();
instance1.defaults.headers.common.Authorization = 'faketoken';
instance2.defaults.headers.common.Authorization = 'differentfaketoken';
instance1.defaults.headers.common['Content-Type'] = 'application/xml';
instance2.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
expect(axios.defaults.headers.common.Authorization).toBe(undefined);
expect(instance1.defaults.headers.common.Authorization).toBe('faketoken');
expect(instance2.defaults.headers.common.Authorization).toBe('differentfaketoken');
expect(axios.defaults.headers.common['Content-Type']).toBe(undefined);
expect(instance1.defaults.headers.common['Content-Type']).toBe('application/xml');
expect(instance2.defaults.headers.common['Content-Type']).toBe('application/x-www-form-urlencoded');
});
});