Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
exotic / __tests__ / is / simple.ts
Size: Mime:
import 'jest'
import stress from '../../__jest/stress'
import {
  isObj,
  isDate,
  isRegExp,
  isArray,
  isError,
  isFunction,
  isNil,
} from '../../src'

describe('simple', () => {
  it('should work for objects', () => {
    function Test() {}
    const instance = new Test()
    const literal = {}
    const create = Object.create(null)

    expect(isObj(instance)).toBe(true)
    expect(isObj(literal)).toBe(true)
    expect(isObj(create)).toBe(true)
    stress(isObj)
  })

  it('should work for dates', () => {
    expect(isDate(new Date())).toBe(true)
    expect(isObj(new Date())).toBe(true)
    stress(isDate)
  })

  it('should work for arrays', () => {
    expect(isArray([])).toBe(true)
    expect(isArray([1, 2, 3])).toBe(true)
    expect(isArray(new Array())).toBe(true)
    expect(isObj(new Array())).toBe(true)
    stress(isArray)
  })

  it('should work for regular expressions', () => {
    expect(isRegExp(/[\s\S]+/)).toBe(true)
    expect(isRegExp(new RegExp('^' + 'foo$'))).toBe(true)
    stress(isRegExp)
  })

  it('should not mark regular expressions as Functions, but they are PureObjects', () => {
    expect(isFunction(/[\s\S]+/)).toBe(false)
    expect(isFunction(new RegExp('^' + 'foo$'))).toBe(false)
    expect(isObj(/[\s\S]+/)).toBe(true)
    expect(isObj(new RegExp('^' + 'foo$'))).toBe(true)
  })

  it('should work for functions', () => {
    expect(isFunction(t => {})).toBe(true)
    expect(isFunction(new Function())).toBe(true)
    stress(isFunction)
  })

  it('should work for Errors', () => {
    expect(isError(new Error(''))).toBe(true)
    expect(isObj(new Error(''))).toBe(true)
    stress(isError)
  })

  // it('isNill', () => {
  //   eq(isNil(void 0), true)
  //   eq(isNil(null), true)
  //   eq(isNil([]), false)
  //   eq(isNil({}), false)
  //   eq(isNil(0), false)
  //   eq(isNil(''), false)
  // })
})