UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

49 lines (39 loc) 1.2 kB
import { filterObj, mapKeys } from "../index"; const obj = { prop: "foo", arr: ["foo", "bar"], bool: true, meaningOfLife: 42, }; describe("filter object", () => { it("is a curried function", () => { expect(filterObj(jest.fn())).toBeFunction(); }); it("filters an object based on the provided predicate", () => { const predicate = jest.fn((key, val) => Array.isArray(val)); const result = filterObj(predicate, obj); expect(predicate).toHaveBeenCalledTimes(Object.keys(obj).length); expect(result).toEqual({ arr: ["foo", "bar"] }); }); it("filters on the object keys too", () => { const predicate = (str) => str.length === 4; const result = filterObj(predicate, obj); expect(result).toEqual({ prop: "foo", bool: true, }); }); }); describe("mapKeys", () => { it("maps over the keys of an object", () => { const mapper = jest.fn((key) => key.toUpperCase()); const result = mapKeys(mapper, obj); expect(mapper).toHaveBeenCalledTimes(Object.keys(obj).length); expect(result).toEqual({ PROP: obj.prop, ARR: obj.arr, BOOL: obj.bool, MEANINGOFLIFE: obj.meaningOfLife, }); }); });