2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00
Files
axios/test/specs/utils/isX.spec.js
T
Avindra Goolcharan 189b34c45a Update Webpack + deps, remove now unnecessary polyfills (#2410)
* Update deps

 * handles webpack 1 -> 4 migration

* remove promise helpers from dev files

assume `Promise` is available, or polyfilled by
the consumer

* Remove isArray util. `isArray` has good coverage, even
   in IE9. So lets remove the custom polyfill.

 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray

also resolves a few lint issues

* Remove trim util

String.protoype.trim has good coverage (including IE9)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim

Also, the http adapter already uses the native method.
2019-10-21 15:56:29 -03:00

62 lines
1.9 KiB
JavaScript

var utils = require('../../../lib/utils');
var Stream = require('stream');
describe('utils::isX', function () {
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(null)).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);
});
});