openpencil/tests/helpers/assert.ts
Danila Poyarkov 51eae14e4b chore(tests): remove targeted non-null assertions
- Add shared test helpers for required nodes and child ids
- Clean non-null assertions from noisy render, nudge, text undo, and fig roundtrip tests
- Enforce the non-null assertion ban for the cleaned test files
- Remove stale eslint disables around empty functions and broad mock transport typing
2026-05-06 01:14:50 +03:00

17 lines
546 B
TypeScript

import type { SceneGraph, SceneNode } from '@open-pencil/core'
export function expectDefined<T>(value: T | null | undefined, label = 'value'): NonNullable<T> {
if (value == null) {
throw new Error(`${label} was expected to be defined`)
}
return value
}
export function getNodeOrThrow(graph: SceneGraph, id: string): SceneNode {
return expectDefined(graph.getNode(id), `node ${id}`)
}
export function childIdAt(node: SceneNode, index: number): string {
return expectDefined(node.childIds[index], `child ${index} of ${node.id}`)
}