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    
chain-able-deps / src / util / __tests__ / values.ts
Size: Mime:
import valuesIn from '../../src/util/valuesIn'
import values from '../../src/util/values'
import keys from '../../src/util/keys'
import repeat from '../../src/fp/repeat'
import map from '../../src/loop/fantasy/_map'
// const indexOf = require('../../src/fp/indexOf')

const indexOf = (needle, haystack) => haystack.indexOf(needle)

describe('valuesIn', () => {
  const obj = {
    a: 100,
    b: [1, 2, 3],
    c: { x: 200, y: 300 },
    d: 'D',
    e: null,
    f: undefined,
  }
  function C() {
    this.a = 100
    this.b = 200
  }
  C.prototype.x = () => 'x'
  C.prototype.y = 'y'
  const cobj = new C()

  it("returns an array of the given object's values", () => {
    const vs = valuesIn(obj)
    eq(vs.length, 6)
    eq(indexOf(100, vs) >= 0, true)
    eq(indexOf('D', vs) >= 0, true)
    eq(indexOf(null, vs) >= 0, true)
    eq(indexOf(undefined, vs) >= 0, true)
    eq(indexOf(obj.b, vs) >= 0, true)
    eq(indexOf(obj.c, vs) >= 0, true)
  })

  it("includes the given object's prototype properties", () => {
    const vs = valuesIn(cobj)
    eq(vs.length, 4)
    eq(indexOf(100, vs) >= 0, true)
    eq(indexOf(200, vs) >= 0, true)
    eq(indexOf(cobj.x, vs) >= 0, true)
    eq(indexOf('y', vs) >= 0, true)
  })

  it.skip('works for primitives', () => {
    const result = map(val => valuesIn(val), [
      null,
      undefined,
      55,
      '',
      true,
      false,
      NaN,
      Infinity,
      ,
      [],
    ])
    eq(result, repeat([], 10))
  })
})

describe('values', () => {
  const obj = {
    a: 100,
    b: [1, 2, 3],
    c: { x: 200, y: 300 },
    d: 'D',
    e: null,
    f: undefined,
  }

  class C {
    constructor() {
      this.a = 100
      this.b = 200
    }

    x() {
      return 'x'
    }
  }

  C.prototype.y = 'y'
  const cobj = new C()

  it("returns an array of the given object's values", () => {
    const vs = values(obj).sort()
    const ts = [[1, 2, 3], 100, 'D', { x: 200, y: 300 }, null, undefined]
    eq(vs.length, ts.length)
    eq(vs[0], ts[0])
    eq(vs[1], ts[1])
    eq(vs[2], ts[2])
    eq(vs[3], ts[3])
    eq(vs[4], ts[4])
    eq(vs[5], ts[5])

    eq(
      values({
        hasOwnProperty: false,
      }),
      [false]
    )
  })

  it("does not include the given object's prototype properties", () => {
    eq(values(cobj), [100, 200])
  })

  it.skip('returns an empty object for primitives', () => {
    const result = map(val => keys(val), [
      null,
      undefined,
      55,
      '',
      true,
      false,
      NaN,
      Infinity,
      ,
      [],
    ])
    eq(result, repeat([], 10))
  })
})