mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
6b9b05b907
* Fixed isFormData predicate;
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment through `form-data` package;
* Added the `form-data` package as a dependency for the server build;
Added tests for FormData payload;
* Added FormData automatic serialization section;
Refactored cancellation section;
* Reworked toFormData helper;
Expose toFormData helper as a static method;
Refactored transform request;
Added kindOf, kindOfTest, endsWith, isTypedArray util;
Refactored utils.js to use kindOf for tests;
* Fixed isFormData predicate; (#4413)
Added support for automatic object serialization to FormData if `Content-Type` is `multipart/form-data`;
Added support for FormData to be overloaded using `config.env.FormData` option;
Added support for FormData in node.js environment using `form-data` package;
(cherry picked from commit 73e3bdb883)
* Added shortcut methods `postForm`, `putForm`, `patchForm` to submit a Form;
Added ability to submit FileList object as a FormData;
Updated README.md;
* Updated README.md;
118 lines
2.6 KiB
JavaScript
118 lines
2.6 KiB
JavaScript
describe('instance', function () {
|
|
beforeEach(function () {
|
|
jasmine.Ajax.install();
|
|
});
|
|
|
|
afterEach(function () {
|
|
jasmine.Ajax.uninstall();
|
|
});
|
|
|
|
it('should have the same methods as default instance', function () {
|
|
var instance = axios.create();
|
|
|
|
for (var prop in axios) {
|
|
if ([
|
|
'Axios',
|
|
'create',
|
|
'Cancel',
|
|
'CancelToken',
|
|
'isCancel',
|
|
'all',
|
|
'spread',
|
|
'isAxiosError',
|
|
'VERSION',
|
|
'default',
|
|
'toFormData'
|
|
].indexOf(prop) > -1) {
|
|
continue;
|
|
}
|
|
expect(typeof instance[prop]).toBe(typeof axios[prop]);
|
|
}
|
|
});
|
|
|
|
it('should make an http request without verb helper', function (done) {
|
|
var instance = axios.create();
|
|
|
|
instance('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
expect(request.url).toBe('/foo');
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should make an http request with url instead of baseURL', function (done) {
|
|
var instance = axios.create({
|
|
url: 'https://api.example.com'
|
|
});
|
|
|
|
instance('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
expect(request.url).toBe('/foo');
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should make an http request', function (done) {
|
|
var instance = axios.create();
|
|
|
|
instance.get('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
expect(request.url).toBe('/foo');
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should use instance options', function (done) {
|
|
var instance = axios.create({ timeout: 1000 });
|
|
|
|
instance.get('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
expect(request.timeout).toBe(1000);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should have defaults.headers', function () {
|
|
var instance = axios.create({
|
|
baseURL: 'https://api.example.com'
|
|
});
|
|
|
|
expect(typeof instance.defaults.headers, 'object');
|
|
expect(typeof instance.defaults.headers.common, 'object');
|
|
});
|
|
|
|
it('should have interceptors on the instance', function (done) {
|
|
axios.interceptors.request.use(function (config) {
|
|
config.foo = true;
|
|
return config;
|
|
});
|
|
|
|
var instance = axios.create();
|
|
instance.interceptors.request.use(function (config) {
|
|
config.bar = true;
|
|
return config;
|
|
});
|
|
|
|
var response;
|
|
instance.get('/foo').then(function (res) {
|
|
response = res;
|
|
});
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
request.respondWith({
|
|
status: 200
|
|
});
|
|
|
|
setTimeout(function () {
|
|
expect(response.config.foo).toEqual(undefined);
|
|
expect(response.config.bar).toEqual(true);
|
|
done();
|
|
}, 100);
|
|
});
|
|
});
|
|
});
|