mirror of
https://github.com/tenrok/axios.git
synced 2026-05-30 15:24:11 +03:00
Updating karma
This commit is contained in:
+3
-3
@@ -37,9 +37,9 @@
|
||||
"grunt-ts": "^1.12.1",
|
||||
"grunt-update-json": "^0.1.3",
|
||||
"grunt-webpack": "^1.0.8",
|
||||
"karma": "^0.12.21",
|
||||
"karma-jasmine": "^0.1.5",
|
||||
"karma-jasmine-ajax": "^0.1.4",
|
||||
"karma": "^0.12.31",
|
||||
"karma-jasmine": "^0.3.5",
|
||||
"karma-jasmine-ajax": "^0.1.11",
|
||||
"karma-phantomjs-launcher": "^0.1.4",
|
||||
"load-grunt-tasks": "^0.6.0",
|
||||
"webpack": "^1.4.0-beta9",
|
||||
|
||||
+182
-229
@@ -9,126 +9,113 @@ describe('interceptors', function () {
|
||||
axios.interceptors.response.handlers = [];
|
||||
});
|
||||
|
||||
it('should add a request interceptor', function () {
|
||||
it('should add a request interceptor', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.test = 'added by interceptor';
|
||||
return config;
|
||||
});
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.test = 'added by interceptor';
|
||||
return config;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
|
||||
expect(request.requestHeaders.test).toBe('added by interceptor');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should add a request interceptor that returns a new config object', function () {
|
||||
it('should add a request interceptor that returns a new config object', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.request.use(function () {
|
||||
return {
|
||||
url: '/bar',
|
||||
method: 'post'
|
||||
};
|
||||
});
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
axios.interceptors.request.use(function () {
|
||||
return {
|
||||
url: '/bar',
|
||||
method: 'post'
|
||||
};
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
|
||||
expect(request.method).toBe('POST');
|
||||
expect(request.url).toBe('/bar');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should add a request interceptor that returns a promise', function () {
|
||||
it('should add a request interceptor that returns a promise', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.request.use(function (config) {
|
||||
return new Promise(function (resolve) {
|
||||
// do something async
|
||||
setTimeout(function () {
|
||||
config.headers.async = 'promise';
|
||||
resolve(config);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
axios.interceptors.request.use(function (config) {
|
||||
return new Promise(function (resolve) {
|
||||
// do something async
|
||||
setTimeout(function () {
|
||||
config.headers.async = 'promise';
|
||||
resolve(config);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
|
||||
expect(request.requestHeaders.async).toBe('promise');
|
||||
});
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('should add multiple request interceptors', function () {
|
||||
it('should add multiple request interceptors', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.test1 = '1';
|
||||
return config;
|
||||
});
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.test2 = '2';
|
||||
return config;
|
||||
});
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.test3 = '3';
|
||||
return config;
|
||||
});
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.test1 = '1';
|
||||
return config;
|
||||
});
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.test2 = '2';
|
||||
return config;
|
||||
});
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers.test3 = '3';
|
||||
return config;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
@@ -136,210 +123,176 @@ describe('interceptors', function () {
|
||||
expect(request.requestHeaders.test1).toBe('1');
|
||||
expect(request.requestHeaders.test2).toBe('2');
|
||||
expect(request.requestHeaders.test3).toBe('3');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should add a response interceptor', function () {
|
||||
it('should add a response interceptor', function (done) {
|
||||
var request, response;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + ' - modified by interceptor';
|
||||
return data;
|
||||
});
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + ' - modified by interceptor';
|
||||
return data;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return response;
|
||||
}, 'waiting for the response', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(response.data).toBe('OK - modified by interceptor');
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
expect(response.data).toBe('OK - modified by interceptor');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should add a response interceptor that returns a new data object', function () {
|
||||
it('should add a response interceptor that returns a new data object', function (done) {
|
||||
var request, response;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.response.use(function () {
|
||||
return {
|
||||
data: 'stuff'
|
||||
};
|
||||
});
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
axios.interceptors.response.use(function () {
|
||||
return {
|
||||
data: 'stuff'
|
||||
};
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return response;
|
||||
}, 'waiting for the response', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(response.data).toBe('stuff');
|
||||
});
|
||||
setTimeout(function () {
|
||||
expect(response.data).toBe('stuff');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should add a response interceptor that returns a promise', function () {
|
||||
it('should add a response interceptor that returns a promise', function (done) {
|
||||
var request, response;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.response.use(function (data) {
|
||||
return new Promise(function (resolve) {
|
||||
// do something async
|
||||
setTimeout(function () {
|
||||
data.data = 'you have been promised!';
|
||||
resolve(data);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
axios.interceptors.response.use(function (data) {
|
||||
return new Promise(function (resolve) {
|
||||
// do something async
|
||||
setTimeout(function () {
|
||||
data.data = 'you have been promised!';
|
||||
resolve(data);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return response;
|
||||
}, 'waiting for the response', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(response.data).toBe('you have been promised!');
|
||||
});
|
||||
setTimeout(function () {
|
||||
expect(response.data).toBe('you have been promised!');
|
||||
done();
|
||||
}, 100);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should add multiple response interceptors', function () {
|
||||
it('should add multiple response interceptors', function (done) {
|
||||
var request, response;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '1';
|
||||
return data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '2';
|
||||
return data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '3';
|
||||
return data;
|
||||
});
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '1';
|
||||
return data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '2';
|
||||
return data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '3';
|
||||
return data;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return response;
|
||||
}, 'waiting for the response', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(response.data).toBe('OK123');
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
expect(response.data).toBe('OK123');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should allow removing interceptors', function () {
|
||||
it('should allow removing interceptors', function (done) {
|
||||
var request, response, intercept;
|
||||
|
||||
runs(function () {
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '1';
|
||||
return data;
|
||||
});
|
||||
intercept = axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '2';
|
||||
return data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '3';
|
||||
return data;
|
||||
});
|
||||
|
||||
axios.interceptors.response.eject(intercept);
|
||||
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '1';
|
||||
return data;
|
||||
});
|
||||
intercept = axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '2';
|
||||
return data;
|
||||
});
|
||||
axios.interceptors.response.use(function (data) {
|
||||
data.data = data.data + '3';
|
||||
return data;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
axios.interceptors.response.eject(intercept);
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: 'OK'
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return response;
|
||||
}, 'waiting for the response', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(response.data).toBe('OK13');
|
||||
});
|
||||
setTimeout(function () {
|
||||
expect(response.data).toBe('OK13');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
+38
-50
@@ -7,85 +7,73 @@ describe('options', function () {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should default method to get', function () {
|
||||
it('should default method to get', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.method).toBe('GET');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should accept headers', function () {
|
||||
it('should accept headers', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
});
|
||||
axios({
|
||||
url: '/foo',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.requestHeaders['X-Requested-With']).toEqual('XMLHttpRequest');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should accept params', function () {
|
||||
it('should accept params', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo',
|
||||
params: {
|
||||
foo: 123,
|
||||
bar: 456
|
||||
}
|
||||
});
|
||||
axios({
|
||||
url: '/foo',
|
||||
params: {
|
||||
foo: 123,
|
||||
bar: 456
|
||||
}
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.url).toBe('/foo?foo=123&bar=456');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should allow overriding default headers', function () {
|
||||
it('should allow overriding default headers', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo',
|
||||
headers: {
|
||||
'Accept': 'foo/bar'
|
||||
}
|
||||
});
|
||||
axios({
|
||||
url: '/foo',
|
||||
headers: {
|
||||
'Accept': 'foo/bar'
|
||||
}
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.requestHeaders['Accept']).toEqual('foo/bar');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
+45
-65
@@ -7,96 +7,79 @@ describe('promise', function () {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should provide succinct object to then', function () {
|
||||
it('should provide succinct object to then', function (done) {
|
||||
var request, response;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (r) {
|
||||
response = r;
|
||||
});
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).then(function (r) {
|
||||
response = r;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: '{"hello":"world"}'
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return response;
|
||||
}, 'waiting for the response', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(typeof response).toEqual('object');
|
||||
expect(response.data.hello).toEqual('world');
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['content-type']).toEqual('application/json');
|
||||
expect(response.config.url).toEqual('/foo');
|
||||
});
|
||||
setTimeout(function () {
|
||||
expect(typeof response).toEqual('object');
|
||||
expect(response.data.hello).toEqual('world');
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.headers['content-type']).toEqual('application/json');
|
||||
expect(response.config.url).toEqual('/foo');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should provide verbose arguments to success', function () {
|
||||
it('should provide verbose arguments to success', function (done) {
|
||||
var request, data, status, headers, config;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).success(function (d, s, h, c) {
|
||||
data = d;
|
||||
status = s;
|
||||
headers = h;
|
||||
config = c;
|
||||
fulfilled = true;
|
||||
});
|
||||
axios({
|
||||
url: '/foo'
|
||||
}).success(function (d, s, h, c) {
|
||||
data = d;
|
||||
status = s;
|
||||
headers = h;
|
||||
config = c;
|
||||
fulfilled = true;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
responseText: '{"hello":"world"}'
|
||||
});
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return data;
|
||||
}, 'waiting for the data', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(data.hello).toEqual('world');
|
||||
expect(status).toBe(200);
|
||||
expect(headers['content-type']).toEqual('application/json');
|
||||
expect(config.url).toEqual('/foo');
|
||||
});
|
||||
setTimeout(function () {
|
||||
expect(data.hello).toEqual('world');
|
||||
expect(status).toBe(200);
|
||||
expect(headers['content-type']).toEqual('application/json');
|
||||
expect(config.url).toEqual('/foo');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should support all', function () {
|
||||
it('should support all', function (done) {
|
||||
var fulfilled = false;
|
||||
|
||||
axios.all([true, 123]).then(function () {
|
||||
fulfilled = true;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return fulfilled;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
setTimeout(function () {
|
||||
expect(fulfilled).toEqual(true);
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should support spread', function () {
|
||||
it('should support spread', function (done) {
|
||||
var sum = 0;
|
||||
var fulfilled = false;
|
||||
|
||||
@@ -105,13 +88,10 @@ describe('promise', function () {
|
||||
fulfilled = true;
|
||||
}));
|
||||
|
||||
waitsFor(function () {
|
||||
return fulfilled;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
setTimeout(function () {
|
||||
expect(fulfilled).toEqual(true);
|
||||
expect(sum).toEqual(123 + 456);
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,102 +7,90 @@ describe('transform', function () {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should transform JSON to string', function () {
|
||||
it('should transform JSON to string', function (done) {
|
||||
var request;
|
||||
var data = {
|
||||
foo: 'bar'
|
||||
};
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo',
|
||||
method: 'post',
|
||||
data: data
|
||||
});
|
||||
axios({
|
||||
url: '/foo',
|
||||
method: 'post',
|
||||
data: data
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.params).toEqual('{"foo":"bar"}');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should override default transform', function () {
|
||||
it('should override default transform', function (done) {
|
||||
var request;
|
||||
var data = {
|
||||
foo: 'bar'
|
||||
};
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo',
|
||||
method: 'post',
|
||||
data: data,
|
||||
transformRequest: function (data) {
|
||||
return data;
|
||||
}
|
||||
});
|
||||
axios({
|
||||
url: '/foo',
|
||||
method: 'post',
|
||||
data: data,
|
||||
transformRequest: function (data) {
|
||||
return data;
|
||||
}
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(typeof request.params).toEqual('object');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should allow an Array of transformers', function () {
|
||||
it('should allow an Array of transformers', function (done) {
|
||||
var request;
|
||||
var data = {
|
||||
foo: 'bar'
|
||||
};
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo',
|
||||
method: 'post',
|
||||
data: data,
|
||||
transformRequest: axios.defaults.transformRequest.concat(
|
||||
function (data) {
|
||||
return data.replace('bar', 'baz');
|
||||
}
|
||||
)
|
||||
});
|
||||
axios({
|
||||
url: '/foo',
|
||||
method: 'post',
|
||||
data: data,
|
||||
transformRequest: axios.defaults.transformRequest.concat(
|
||||
function (data) {
|
||||
return data.replace('bar', 'baz');
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.params).toEqual('{"foo":"baz"}');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should allowing mutating headers', function () {
|
||||
it('should allowing mutating headers', function (done) {
|
||||
var token = Math.floor(Math.random() * Math.pow(2, 64)).toString(36);
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo',
|
||||
transformRequest: function (data, headers) {
|
||||
headers['X-Authorization'] = token;
|
||||
}
|
||||
});
|
||||
axios({
|
||||
url: '/foo',
|
||||
transformRequest: function (data, headers) {
|
||||
headers['X-Authorization'] = token;
|
||||
}
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.requestHeaders['X-Authorization']).toEqual(token);
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
+87
-106
@@ -7,199 +7,180 @@ describe('wrapper', function () {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should make an http request', function () {
|
||||
it('should make an http request', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.url).toBe('/foo')
|
||||
});
|
||||
expect(request.url).toBe('/foo');
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should default common headers', function () {
|
||||
it('should default common headers', function (done) {
|
||||
var request;
|
||||
var headers = axios.defaults.headers.common;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
for (var key in headers) {
|
||||
if (headers.hasOwnProperty(key)) {
|
||||
expect(request.requestHeaders[key]).toEqual(headers[key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should add extra headers for post', function () {
|
||||
it('should add extra headers for post', function (done) {
|
||||
var request;
|
||||
var headers = axios.defaults.headers.common;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo',
|
||||
data: 'fizz=buzz'
|
||||
});
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo',
|
||||
data: 'fizz=buzz'
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
for (var key in headers) {
|
||||
if (headers.hasOwnProperty(key)) {
|
||||
expect(request.requestHeaders[key]).toEqual(headers[key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should use application/json when posting an object', function () {
|
||||
it('should use application/json when posting an object', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo/bar',
|
||||
method: 'post',
|
||||
data: {
|
||||
firstName: 'foo',
|
||||
lastName: 'bar'
|
||||
}
|
||||
});
|
||||
axios({
|
||||
url: '/foo/bar',
|
||||
method: 'post',
|
||||
data: {
|
||||
firstName: 'foo',
|
||||
lastName: 'bar'
|
||||
}
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.requestHeaders['Content-Type']).toEqual('application/json;charset=utf-8');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should support binary data as array buffer', function () {
|
||||
it('should support binary data as array buffer', function (done) {
|
||||
var request;
|
||||
var input = new Int8Array(2);
|
||||
input[0] = 1;
|
||||
input[1] = 2;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo',
|
||||
data: input.buffer
|
||||
});
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo',
|
||||
data: input.buffer
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
var output = new Int8Array(request.params.buffer);
|
||||
expect(output.length).toEqual(2);
|
||||
expect(output[0]).toEqual(1);
|
||||
expect(output[1]).toEqual(2);
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should support binary data as array buffer view', function () {
|
||||
it('should support binary data as array buffer view', function (done) {
|
||||
var request;
|
||||
var input = new Int8Array(2);
|
||||
input[0] = 1;
|
||||
input[1] = 2;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo',
|
||||
data: input
|
||||
});
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo',
|
||||
data: input
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
var output = new Int8Array(request.params.buffer);
|
||||
expect(output.length).toEqual(2);
|
||||
expect(output[0]).toEqual(1);
|
||||
expect(output[1]).toEqual(2);
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should remove content-type if data is empty', function () {
|
||||
it('should remove content-type if data is empty', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo'
|
||||
});
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.requestHeaders['content-type']).toEqual(undefined);
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
// TODO this won't work until karma-jasmine updates to jasmine-ajax 2.99.0
|
||||
/*
|
||||
it('should support array buffer response', function () {
|
||||
it('should support array buffer response', function (done) {
|
||||
var request, response;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo',
|
||||
responseType: 'arraybuffer'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
function str2ab(str) {
|
||||
var buff = new ArrayBuffer(str.length * 2);
|
||||
var view = new Uint16Array(buff);
|
||||
for ( var i=0, l=str.length; i<l; i++) {
|
||||
view[i] = str.charCodeAt(i);
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
axios({
|
||||
url: '/foo',
|
||||
responseType: 'arraybuffer'
|
||||
}).then(function (data) {
|
||||
response = data;
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
request.response({
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
response: new ArrayBuffer(16)
|
||||
response: str2ab('Hello world')
|
||||
});
|
||||
request.response = new ArrayBuffer(16);
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return response;
|
||||
}, 'waiting for the response', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(response.data.byteLength).toBe(16);
|
||||
});
|
||||
setTimeout(function () {
|
||||
console.log(response.data);
|
||||
expect(response.data.byteLength).toBe(16);
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
+14
-20
@@ -8,40 +8,34 @@ describe('xsrf', function () {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should not set xsrf header if cookie is null', function () {
|
||||
it('should not set xsrf header if cookie is null', function (done) {
|
||||
var request;
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual(undefined);
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should set xsrf header if cookie is set', function () {
|
||||
it('should set xsrf header if cookie is set', function (done) {
|
||||
var request;
|
||||
document.cookie = axios.defaults.xsrfCookieName + '=12345';
|
||||
|
||||
runs(function () {
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
axios({
|
||||
url: '/foo'
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return request = jasmine.Ajax.requests.mostRecent();
|
||||
}, 'waiting for the request', 100);
|
||||
setTimeout(function () {
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
|
||||
runs(function () {
|
||||
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual('12345');
|
||||
});
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user