---
title: "Testing"
description: "Terminal apps, written in TypeScript and compiled to native executables with scriptc."
canonical_url: "https://tui-sdk.dev/docs/guides/testing"
---
# Testing

`createTestApp` runs an app on a screen of its own, with nothing written to the terminal. A test presses keys, types, clicks, and reads back what was drawn. It runs under `node --test` or any other runner, and needs no terminal, so it also runs in CI:

```ts
import assert from "node:assert/strict"
import { test } from "node:test"
import { createTestApp, type Frame, Listbox } from "tui"

const fruits = ["apple", "banana", "cherry"].map((value) => ({ value, label: value }))
let picked = ""

function view(frame: Frame) {
  Listbox.Root(frame, { items: fruits, onValueChange: (value) => (picked = value) }, (root) =>
    Listbox.Content(root, frame.rect),
  )
}

test("picking a fruit", () => {
  const app = createTestApp({ columns: 20, rows: 3, mouse: true, view })
  assert.deepEqual(app.screen(), [" apple", " banana", " cherry"])
  app.press("down")
  assert.equal(app.cell(1, 1).inverse, true)
  const at = app.find("cherry")
  assert.ok(at)
  app.click(at.x, at.y)
  assert.equal(picked, "cherry")
})
```

- `press("ctrl+k")` presses a key by its shortcut, `type(text)` types one keystroke at a time, and `input(data)` sends raw terminal input, such as a bracketed paste.
- `click(x, y)` and `wheel(x, y, "down")` work the mouse on a cell, counted from 0 at the top left, in an app with `mouse: true`.
- `screen()` is the screen as lines of text without trailing spaces, `find(text)` is the cell where some text starts, and `cell(x, y)` is one cell's text, colors, attributes, and link.
- `advance(ms)` moves the app's clock, so an app with `fps` draws its next frame and an animation can be tested a step at a time. `resize(columns, rows)` changes the screen's size.
- `focused()` is the id of the part with the focus, `copied()` is what the app put on the clipboard, and `graphics()` is what images sent the terminal.

Each key is drawn before the next one is sent, as a terminal would show it, so what a test reads is always the current screen.
