A useful chart test answers more than “did a surface appear?” Test at the narrowest layer that owns the behavior.
createChartScene gives static definitions a deterministic, DOM-free result:
import { createChartScene } from '@tanstack/charts'
const scene = createChartScene(definition, {
width: 640,
height: 360,
})
expect(scene.points).toHaveLength(rows.length)
expect(scene.scales.x.domain).toEqual(expectedDates)
expect(scene.chart.width).toBeGreaterThan(0)For responsive definitions, create a runtime and call render with an exact surface size. Scene tests are suited to:
Avoid asserting the complete scene object when only one semantic invariant matters.
Use renderChartSvg to verify:
Prefer structural assertions over a full string snapshot. A formatting change should not obscure a geometry regression.
Mount into a real or sufficiently complete DOM when behavior depends on:
Always call destroy() and verify observers, frames, tooltip nodes, and event listeners do not survive.
Run the same focus, keyboard, tooltip, selection, responsive-update, and destroy sequences against SVG and Canvas when renderer parity matters. Those behaviors belong to the shared host; renderer tests should concentrate on surface adoption, coordinate conversion, paint, and cleanup.
For Canvas, test deterministic server-shell markup without installing Canvas APIs. Use a Canvas 2D mock for draw-call and device-pixel-ratio assertions, then use browser screenshots for representative paths, clipping, gradients, text, themes, and focus-overlay composition. Do not use a raw pixel or data-URL snapshot as the only semantic assertion.
Describe the user path and its semantic assertion:
This catches state-preservation failures that a static screenshot cannot.
Use screenshots for painted properties that are hard to express as numbers:
Fix fonts, viewport, device scale, animation state, locale, time zone, and data revision. Pair the screenshot with geometry assertions so a visually small but semantically important error cannot hide in the diff threshold.
At minimum verify:
See Accessibility.
When output is wrong, inspect in this order:
If the scene is correct but the surface is wrong, the defect belongs to rendering, reconciliation or paint, or styling. If the channel values are wrong, changing the renderer will not fix the cause.
A timed run is valid only if it also verifies:
Exclude invalid attempts from rankings. Report warmup, sample count, percentile, environment, data size, and renderer capability. See Bundle Size and Performance.