ptitlutins/test/utils/childrenOf.test.ts
2026-06-10 23:37:21 +02:00

20 lines
696 B
TypeScript

import { describe, it, expect } from "vitest"
import { childrenOf } from "../../app/utils/childrenOf"
describe("childrenOf", () => {
it("returns the children array of a node that has children", () => {
const child = { id: "c1", title: "Child", children: [] } as any
const node = { id: "n1", title: "Parent", children: [child] } as any
expect(childrenOf(node)).toBe(node.children)
expect(childrenOf(node)).toEqual([child])
})
it("returns [] for a node without children", () => {
const node = { id: "n1", title: "No kids" } as any
expect(childrenOf(node)).toEqual([])
})
it("returns [] for a null node", () => {
expect(childrenOf(null)).toEqual([])
})
})