Skip to content

@boundsvg/testing ​

Testing helpers for snapshot stability and render diagnostics. Use this package in application test suites so tests can assert the output you care about without depending on internal engine details.

Snapshot Helpers ​

ts
import {
  assertNoWarnings,
  assertStableNodeIds,
  normalizeSvg,
  renderMatrix,
  renderSvgSnapshot,
} from "@boundsvg/testing";

assertStableNodeIds(vnode);

const svg = renderSvgSnapshot(engine, vnode);
expect(svg).toMatchSnapshot();

const cases = renderMatrix(engine, [
  { name: "default", input: vnode },
  { name: "glyph paths", input: vnode, options: { textPathMode: "glyphs" } },
]);

expect(cases.map((entry) => entry.normalizedSvg)).toMatchSnapshot();
APIDescription
normalizeSvgSorts tag attributes and rounds long decimal values for stable snapshots
createTestEngineThin wrapper around createEngine for tests that inject mock engines
renderSvgSnapshotRenders SVG and normalizes it
renderPngSnapshotRenders PNG and returns bytes plus header dimensions
assertNoWarningsThrows when an IR contains recoverable render warnings
assertStableNodeIdsThrows when a VNode tree contains duplicate explicit node IDs
renderMatrixRenders named cases and returns normalized SVG strings with warning counts

Vitest Matchers ​

Vitest integration lives in a separate subpath so the root testing helpers do not require a test runner at runtime.

ts
import { expect } from "vitest";
import { boundsvgMatchers } from "@boundsvg/testing/vitest";

expect.extend(boundsvgMatchers);