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__ / keys.ts
Size: Mime:
import keysIn from '../../src/util/keysIn'
import keys from '../../src/util/keys'
import repeat from '../../src/fp/repeat'
import map from '../../src/loop/fantasy/_map'

const eq = (x, y, msg) => expect(x).toEqual(y)
// eslint-disable-next-line
const PRIMITIVES_LIST = [
  null,
  undefined,
  55,
  '',
  true,
  false,
  NaN,
  Infinity,
  ,
  [],
]

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()

describe('keysIn', () => {
  it("returns an array of the given object's keys", () => {
    eq(keysIn(obj).sort(), ['a', 'b', 'c', 'd', 'e', 'f'])
  })

  it("includes the given object's prototype properties", () => {
    eq(keysIn(cobj).sort(), ['a', 'b', 'x', 'y'])
  })
  it('ignores proto with guard', () => {
    eq(keysIn(cobj, true).sort(), ['a', 'b'])
  })

  it.skip('works for primitives', () => {
    const result = map(val => keysIn(val), PRIMITIVES_LIST)
    eq(result, repeat([], 10))
  })
})

describe('keys', () => {
  it("returns an array of the given object's own keys", () => {
    eq(keys(obj).sort(), ['a', 'b', 'c', 'd', 'e', 'f'])
  })

  it('works with hasOwnProperty override', () => {
    eq(
      keys({
        hasOwnProperty: false,
      }),
      ['hasOwnProperty']
    )
  })

  it.skip('works for primitives', () => {
    const result = map(val => keys(val), PRIMITIVES_LIST)
    eq(result, repeat([], 10))
  })

  it("does not include the given object's prototype properties", () => {
    eq(keys(cobj).sort(), ['a', 'b'])
  })
})