mirror of
https://github.com/axios/axios.git
synced 2026-04-14 03:11:58 +08:00
* 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;
86 lines
2.8 KiB
JavaScript
86 lines
2.8 KiB
JavaScript
var utils = require('../../../lib/utils');
|
|
var Stream = require('stream');
|
|
|
|
describe('utils::isX', function () {
|
|
it('should validate Array', function () {
|
|
expect(utils.isArray([])).toEqual(true);
|
|
expect(utils.isArray({length: 5})).toEqual(false);
|
|
});
|
|
|
|
it('should validate Buffer', function () {
|
|
expect(utils.isBuffer(Buffer.from('a'))).toEqual(true);
|
|
expect(utils.isBuffer(null)).toEqual(false);
|
|
expect(utils.isBuffer(undefined)).toEqual(false);
|
|
});
|
|
|
|
it('should validate ArrayBuffer', function () {
|
|
expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true);
|
|
expect(utils.isArrayBuffer({})).toEqual(false);
|
|
});
|
|
|
|
it('should validate ArrayBufferView', function () {
|
|
expect(utils.isArrayBufferView(new DataView(new ArrayBuffer(2)))).toEqual(true);
|
|
});
|
|
|
|
it('should validate FormData', function () {
|
|
expect(utils.isFormData(new FormData())).toEqual(true);
|
|
});
|
|
|
|
it('should validate Blob', function () {
|
|
expect(utils.isBlob(new Blob())).toEqual(true);
|
|
});
|
|
|
|
it('should validate String', function () {
|
|
expect(utils.isString('')).toEqual(true);
|
|
expect(utils.isString({toString: function () { return ''; }})).toEqual(false);
|
|
});
|
|
|
|
it('should validate Number', function () {
|
|
expect(utils.isNumber(123)).toEqual(true);
|
|
expect(utils.isNumber('123')).toEqual(false);
|
|
});
|
|
|
|
it('should validate Undefined', function () {
|
|
expect(utils.isUndefined()).toEqual(true);
|
|
expect(utils.isUndefined(null)).toEqual(false);
|
|
});
|
|
|
|
it('should validate Object', function () {
|
|
expect(utils.isObject({})).toEqual(true);
|
|
expect(utils.isObject([])).toEqual(true);
|
|
expect(utils.isObject(null)).toEqual(false);
|
|
});
|
|
|
|
it('should validate plain Object', function () {
|
|
expect(utils.isPlainObject({})).toEqual(true);
|
|
expect(utils.isPlainObject([])).toEqual(false);
|
|
expect(utils.isPlainObject(null)).toEqual(false);
|
|
expect(utils.isPlainObject(Object.create({}))).toEqual(false);
|
|
});
|
|
|
|
it('should validate Date', function () {
|
|
expect(utils.isDate(new Date())).toEqual(true);
|
|
expect(utils.isDate(Date.now())).toEqual(false);
|
|
});
|
|
|
|
it('should validate Function', function () {
|
|
expect(utils.isFunction(function () {})).toEqual(true);
|
|
expect(utils.isFunction('function')).toEqual(false);
|
|
});
|
|
|
|
it('should validate Stream', function () {
|
|
expect(utils.isStream(new Stream.Readable())).toEqual(true);
|
|
expect(utils.isStream({ foo: 'bar' })).toEqual(false);
|
|
});
|
|
|
|
it('should validate URLSearchParams', function () {
|
|
expect(utils.isURLSearchParams(new URLSearchParams())).toEqual(true);
|
|
expect(utils.isURLSearchParams('foo=1&bar=2')).toEqual(false);
|
|
});
|
|
|
|
it('should validate TypedArray instance', function () {
|
|
expect(utils.isTypedArray(new Uint8Array([1, 2, 3]))).toEqual(true);
|
|
expect(utils.isTypedArray([1, 2, 3])).toEqual(false);
|
|
});
|
|
});
|