Skip to content

Snapshots

Snapshot assertions compare the live terminal screen against a checked-in baseline file. Use snapshots to verify full-screen TUI layouts, tables, borders, and styling rules that would be tedious to check cell by cell.

Wait for a known UI state before calling expectSnapshot. On the first run, if no baseline file exists yet, tui-test writes it automatically so you can review and commit it to version control. Subsequent runs compare the current terminal against that file and fail with a diff if they diverge.

await terminal.getByText("Dashboard").expect();
await terminal.expectSnapshot("dashboard-home", {
includeStyle: true,
includeTitle: true,
});
Option CLI flag Behavior
includeStyle --include-style Captures foreground/background colors, underline attributes, and SGR flags alongside text.
includeTitle --include-title Records and checks the terminal’s window title in the snapshot.
cwd --cwd DIR Overrides the root directory used to resolve snapshot baselines (defaults to the caller’s working directory).
update -u, --update Rewrites an existing baseline after an intentional UI change. Turn update back off before committing test code.
await terminal.expectSnapshot("dashboard-home", {
update: true,
includeStyle: true,
cwd: "tests/fixtures",
});
  • Fix cols, rows, and backend in your launch options so terminal line wrapping and Unicode widths match across developer machines and CI runners.
  • Replace variable timestamps, PIDs, or temporary paths in your app’s test fixtures, or normalize raw text strings with terminalSnapshot (JavaScript), terminal_snapshot (Python), or tuitesttest.TerminalSnapshot (Go) when comparing plain text with your test runner’s own assertions.