testing library

Test helpers for dart_tui apps: drive a real Program with keys and messages, read its screen, and compare screens with golden files.

import 'package:dart_tui/dart_tui.dart';
import 'package:dart_tui/testing.dart';

final t = TuiTester(CounterModel());
await t.press('up');
await t.waitFor((screen) => screen.contains('Count: 1'));
expectScreen(t.screen, 'test/goldens/counter.txt');
final result = await t.quit();

It imports no test framework: failures throw TuiTestFailure, so it works with package:test or any other runner.

Classes

CaptureSink
An IOSink that keeps everything written to it in memory, as text.
TuiResult
How a TuiTester run ended.
TuiTester
Runs a Model in a real Program, headless, for tests.

Functions

expectScreen(String actual, String path, {bool? update}) → void
Compares actual with the golden file at path.
keyPressFor(String key) → KeyPressMsg
The KeyPressMsg a terminal produces for the keystroke key (see TuiTester.press).
plainScreen(String content) → String
content without escape codes, and with trailing spaces trimmed on every line. This is TuiTester.screen for any string, such as a view().

Exceptions / Errors

TuiTestFailure
A failed TuiTester.waitFor or expectScreen.