UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

36 lines (28 loc) 1.16 kB
import { findChild } from "../index"; describe("findChild", () => { const makeNode = (children = []) => ({ children }); const child = (preferredFocus: boolean) => ({ component: { props: { preferredFocus } }, }); it("returns the child with preferredFocus=true", () => { const node = makeNode([child(false), child(true), child(false)]); expect(findChild(true, node)).toBe(node.children[1]); }); it("returns the child with preferredFocus=false", () => { const node = makeNode([child(false), child(true), child(false)]); expect(findChild(false, node)).toBe(node.children[0]); }); it("returns undefined if no child matches preferredFocus", () => { const node = makeNode([child(false), child(false)]); expect(findChild(true, node)).toBeUndefined(); }); it("returns undefined if node has no children", () => { const node = makeNode(); expect(findChild(true, node)).toBeUndefined(); expect(findChild(false, node)).toBeUndefined(); }); it("returns undefined if children is not an array", () => { const node = { children: null }; expect(findChild(true, node)).toBeUndefined(); }); });