Headless testing
Choose a fixed viewport with testenv.New, mount the tree, then Flush before reading geometry or screen contents. Assert logical state with Expect and painted output with ExpectScreen: a value can exist in the DOM yet be clipped off screen.
func TestGreeting(t *testing.T) { env := testenv.New(t, 24, 4) label := element.Box("Ready")
env.Mount(label) env.Flush()
testenv.Expect(t, label).ToHaveTextContent("Ready") testenv.ExpectScreen(t, env).ToContainText("Ready")}Drive input
Section titled “Drive input”Focus a control before calling env.Type("hello"). Use env.Play("<Tab>", "<Enter>") for key sequences, or env.Click(x, y) for a mouse interaction in terminal cells. Flush again before assertions. Attach testenv.SpyEvents(t, target, eventType) before sending input, then use AssertFiredCount to distinguish one activation from two. For asynchronous work, use testenv.Eventually(t, predicate, timeout) rather than sleeping for a fixed delay.
Diagnose visual regressions
Section titled “Diagnose visual regressions”env.MatchGolden(t, "greeting") compares the frame with testdata/greeting.golden, creating it if absent. For a deliberate change, run the specific test with go test -timeout 30s -run '^TestGreeting$' -update in its package and inspect the snapshot diff. DumpText() gives a plain grid, DumpANSI() preserves terminal styling, and DumpHTML() produces a browser-viewable representation.
For Kitex components use extras/kitex/kitextest instead of setting up a root yourself:
harness := kitextest.Render(t, kitex.Text("Ready"))testenv.ExpectScreen(t, harness.Env).ToContainText("Ready")Render flushes the first frame and arranges cleanup. Use harness.Rerender(node) to test new props in the same container.