Skip to main content
Module

x/rambda/is.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import { is } from './is'
test('works with built-in types', () => { expect(is(Array, undefined)).toBeFalse() expect(is(Array)([])).toBeTrue() expect(is(Boolean, new Boolean(false))).toBeTrue() expect(is(Date, new Date())).toBeTrue() expect(is(Function, () => {})).toBeTrue() expect(is(Number, new Number(0))).toBeTrue() expect(is(Object, {})).toBeTrue() expect(is(RegExp, /(?:)/)).toBeTrue() expect(is(String, new String(''))).toBeTrue()})
test('works with user-defined types', () => { function Foo(){} function Bar(){} Bar.prototype = new Foo()
const foo = new Foo() const bar = new Bar()
expect(is(Foo, foo)).toBeTrue() expect(is(Bar, bar)).toBeTrue() expect(is(Foo, bar)).toBeTrue() expect(is(Bar, foo)).toBeFalse()})
test('does not coerce', () => { expect(is(Boolean, 1)).toBeFalse() expect(is(Number, '1')).toBeFalse() expect(is(Number, false)).toBeFalse()})
test('recognizes primitives as their object equivalents', () => { expect(is(Boolean, false)).toBeTrue() expect(is(Number, 0)).toBeTrue() expect(is(String, '')).toBeTrue()})
test('does not consider primitives to be instances of Object', () => { expect(is(Object, false)).toBeFalse() expect(is(Object, 0)).toBeFalse() expect(is(Object, '')).toBeFalse()})