UNPKG

@applicaster/zapp-react-native-ui-components

Version:

Applicaster Zapp React Native ui components for the Quick Brick App

51 lines (42 loc) 1.7 kB
import { functionForName, pathWithFallback, stringifyDateFromPath, } from "../../MappingFunctions"; import { entry } from "../../__tests__/testEntry"; describe("functionForName", () => { it("returns a function matching the func name", () => { const myFunction = functionForName("stringify_date_from_path"); expect(myFunction).toBeFunction(); expect(myFunction.name).toBe("stringifyDateFromPath"); }); it("returns 'pathWithFallback' function as a fallback when no matching func name is found", () => { const myFunction = functionForName("does_not_exist"); expect(myFunction.name).toBe("pathWithFallback"); }); it("returns 'pathWithFallback' function as a default", () => { const myFunction = functionForName(undefined); expect(myFunction.name).toBe("pathWithFallback"); }); }); describe("pathWithFallback", () => { it("returns the value found in the obj, according to given path", () => { expect(pathWithFallback(entry, ["author", "name"])).toBe(entry.author.name); }); it("returns an empty string if not found", () => { expect(pathWithFallback(entry, ["does_not_exist"])).toBe(""); }); }); describe("stringifyDateFromPath", () => { it("returns a stringified format of the ISO8061 date found in path", () => { expect(stringifyDateFromPath(entry, ["published"])).toBe( new Date("2019/03/17 02:17:46 +0000").toDateString() ); }); it("returns an empty string if found value is not a valid ISO8061 date", () => { expect(stringifyDateFromPath(entry, ["title"])).toBe(""); }); it("returns an empty string if not found", () => { expect(stringifyDateFromPath(entry, ["does_not_exist"])).toBe(""); }); });