@itsjonq/is
Version:
A tiny type checker
116 lines (108 loc) • 3.94 kB
JavaScript
var _index = require("../index");
test('should test for array', function () {
expect(_index.is.array([])).toBe(true);
expect(_index.is.array('123')).toBe(false);
});
test('should test for Blob', function () {
/* eslint-disable no-undef */
expect(_index.is.blob(new Blob())).toBe(true);
/* eslint-enable no-undef */
expect(_index.is.blob('blob')).toBe(false);
expect(_index.is.blob(123)).toBe(false);
});
test('should test for boolean', function () {
expect(_index.is.boolean(true)).toBe(true);
expect(_index.is.boolean(false)).toBe(true);
expect(_index.is.boolean('123')).toBe(false);
});
test('should test for defined', function () {
expect(_index.is.defined(true)).toBe(true);
expect(_index.is.defined(0)).toBe(true);
expect(_index.is.defined(undefined)).toBe(false);
expect(_index.is.defined(null)).toBe(false);
});
test('should test for File', function () {
/* eslint-disable no-undef */
expect(_index.is.file(new File([''], '', {
type: 'text/html'
}))).toBe(true);
/* eslint-enable no-undef */
expect(_index.is.file('File')).toBe(false);
expect(_index.is.file(123)).toBe(false);
});
test('should test for function', function () {
expect(_index.is.function(function () {})).toBe(true);
expect(_index.is.function(function () {})).toBe(true);
expect(_index.is.function(function () {})).toBe(true);
expect(_index.is.function('123')).toBe(false);
});
test('should test for date', function () {
expect(_index.is.date(new Date())).toBe(true);
expect(_index.is.date('123')).toBe(false);
});
test('should test for map', function () {
/* eslint-disable no-undef */
var o = new Map();
/* eslint-enable no-undef */
expect(_index.is.map(o)).toBe(true);
expect(_index.is.map('123')).toBe(false);
});
test('should test for number', function () {
expect(_index.is.number(0)).toBe(true);
expect(_index.is.number(123)).toBe(true);
expect(_index.is.number('123')).toBe(false);
});
test('should test for null', function () {
expect(_index.is.null(null)).toBe(true);
expect(_index.is.null(undefined)).toBe(false);
expect(_index.is.null('')).toBe(false);
expect(_index.is.null(0)).toBe(false);
});
test('should test for object', function () {
expect(_index.is.object(new Object())).toBe(true);
expect(_index.is.object({})).toBe(true);
expect(_index.is.object(function () {})).toBe(false);
expect(_index.is.object('')).toBe(false);
expect(_index.is.object(0)).toBe(false);
});
test('should test for plainObject', function () {
expect(_index.is.plainObject(new Object())).toBe(true);
expect(_index.is.plainObject({})).toBe(true);
expect(_index.is.plainObject([])).toBe(false);
expect(_index.is.plainObject(function () {})).toBe(false);
expect(_index.is.plainObject('')).toBe(false);
expect(_index.is.plainObject(0)).toBe(false);
});
test('should test for regExp', function () {
/* eslint-disable no-undef */
var o = new RegExp();
/* eslint-enable no-undef */
expect(_index.is.regExp(o)).toBe(true);
expect(_index.is.regExp('123')).toBe(false);
});
test('should test for string', function () {
expect(_index.is.string('Hello')).toBe(true);
expect(_index.is.string('')).toBe(true);
expect(_index.is.string(123)).toBe(false);
});
test('should test for symbol', function () {
/* eslint-disable no-undef */
var o = Symbol();
/* eslint-enable no-undef */
expect(_index.is.symbol(o)).toBe(true);
expect(_index.is.symbol('123')).toBe(false);
});
test('should test for undefined', function () {
expect(_index.is.undefined(undefined)).toBe(true);
expect(_index.is.undefined(null)).toBe(false);
expect(_index.is.undefined('')).toBe(false);
expect(_index.is.undefined(0)).toBe(false);
});
test('should test for weakMap', function () {
/* eslint-disable no-undef */
var o = new WeakMap();
/* eslint-enable no-undef */
expect(_index.is.weakMap(o)).toBe(true);
expect(_index.is.weakMap('123')).toBe(false);
});
;