Skip to content

toMatchTerminalSnapshot

Match the full terminal state against a Vitest snapshot. Captures text content, cursor position, cursor visibility, cursor style, and screen mode.

Signature

typescript
expect(term).toMatchTerminalSnapshot(options?: { name?: string })

Parameters

ParameterTypeDescription
options.namestringOptional snapshot name

Usage

typescript
// Basic snapshot
expect(term).toMatchTerminalSnapshot()

// Named snapshot (for multiple snapshots in one test)
expect(term).toMatchTerminalSnapshot({ name: "after-input" })

Snapshot Format

The snapshot includes a header with terminal dimensions and cursor state, followed by numbered rows:

# terminal 80x24 | cursor (0,0) visible block
──────────────────────────────────────────────────
 1│Hello, World
 2│
 3│Ready

Accepts

TargetSupported
term (TerminalReadable)Yes
term.screenNo
term.cell(r, c)No

Notes

  • Uses Vitest's built-in snapshot machinery
  • Update snapshots with vitest --update
  • For SVG visual snapshots, use toMatchSvgSnapshot

See Also