UNPKG

@itsjonq/is

Version:
113 lines (107 loc) 3.55 kB
import { is } from '../index'; test('should test for array', function () { expect(is.array([])).toBe(true); expect(is.array('123')).toBe(false); }); test('should test for Blob', function () { /* eslint-disable no-undef */ expect(is.blob(new Blob())).toBe(true); /* eslint-enable no-undef */ expect(is.blob('blob')).toBe(false); expect(is.blob(123)).toBe(false); }); test('should test for boolean', function () { expect(is.boolean(true)).toBe(true); expect(is.boolean(false)).toBe(true); expect(is.boolean('123')).toBe(false); }); test('should test for defined', function () { expect(is.defined(true)).toBe(true); expect(is.defined(0)).toBe(true); expect(is.defined(undefined)).toBe(false); expect(is.defined(null)).toBe(false); }); test('should test for File', function () { /* eslint-disable no-undef */ expect(is.file(new File([''], '', { type: 'text/html' }))).toBe(true); /* eslint-enable no-undef */ expect(is.file('File')).toBe(false); expect(is.file(123)).toBe(false); }); test('should test for function', function () { expect(is.function(function () {})).toBe(true); expect(is.function(function () {})).toBe(true); expect(is.function(function () {})).toBe(true); expect(is.function('123')).toBe(false); }); test('should test for date', function () { expect(is.date(new Date())).toBe(true); expect(is.date('123')).toBe(false); }); test('should test for map', function () { /* eslint-disable no-undef */ var o = new Map(); /* eslint-enable no-undef */ expect(is.map(o)).toBe(true); expect(is.map('123')).toBe(false); }); test('should test for number', function () { expect(is.number(0)).toBe(true); expect(is.number(123)).toBe(true); expect(is.number('123')).toBe(false); }); test('should test for null', function () { expect(is.null(null)).toBe(true); expect(is.null(undefined)).toBe(false); expect(is.null('')).toBe(false); expect(is.null(0)).toBe(false); }); test('should test for object', function () { expect(is.object(new Object())).toBe(true); expect(is.object({})).toBe(true); expect(is.object(function () {})).toBe(false); expect(is.object('')).toBe(false); expect(is.object(0)).toBe(false); }); test('should test for plainObject', function () { expect(is.plainObject(new Object())).toBe(true); expect(is.plainObject({})).toBe(true); expect(is.plainObject([])).toBe(false); expect(is.plainObject(function () {})).toBe(false); expect(is.plainObject('')).toBe(false); expect(is.plainObject(0)).toBe(false); }); test('should test for regExp', function () { /* eslint-disable no-undef */ var o = new RegExp(); /* eslint-enable no-undef */ expect(is.regExp(o)).toBe(true); expect(is.regExp('123')).toBe(false); }); test('should test for string', function () { expect(is.string('Hello')).toBe(true); expect(is.string('')).toBe(true); expect(is.string(123)).toBe(false); }); test('should test for symbol', function () { /* eslint-disable no-undef */ var o = Symbol(); /* eslint-enable no-undef */ expect(is.symbol(o)).toBe(true); expect(is.symbol('123')).toBe(false); }); test('should test for undefined', function () { expect(is.undefined(undefined)).toBe(true); expect(is.undefined(null)).toBe(false); expect(is.undefined('')).toBe(false); expect(is.undefined(0)).toBe(false); }); test('should test for weakMap', function () { /* eslint-disable no-undef */ var o = new WeakMap(); /* eslint-enable no-undef */ expect(is.weakMap(o)).toBe(true); expect(is.weakMap('123')).toBe(false); });