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